Python optionparser callback example

Python optionparser callback example

By: xxx-zip Date of post: 18.07.2017

This page contains a bunch of miscellaneous Python code snippets, recipes, mini-guides, links, examples, tutorials and ideas, ranging from very very basic things to advanced. I hope they will be usefull to you. Don't forget to read my main Python page http: Python makes using queues and stacks a piece of cake Did I already say "piece of cake"?

No use creating a specific class: For a stack LIFOstack with append and destack with pop:. For a queue FIFOenqueue with append and dequeue with pop As lists can contain any type of object, you an create queues and stacks of any type of objects! When you're not accustomed with Python, it's easy to forget that a function can return just any type of object, including tuples. This a great to create functions which return several values. This is typically the kind of thing that cannot be done in other languages without some code overhead.

Dive into Python http: The first chapter contains a nice tutorial on tuples, lists and dictionnaries. And don't forget to read the rest of the book You can download the entire book for free. Note that HTMLParser is not bullet-proof: In this case, use the sgmllib module, go back to regular expressions or use BeautifulSoup.

Beautiful Soup is a Python module which is quite good at extracting data from HTML. Beautiful Soup's main advantages are its ability to handle very bad HTML code and its simplicity.

Its drawback is its speed it's slow. You can also use os. This webserver will serve files in the current directory. You can use os. This trick is handy to serve or transfer files between computers on a local network. Note that this webserver is pretty fast, but can only serve one HTTP request at time. It's not recommended for high-traffic servers. If you want better performance, have a look at asynchronous sockets asyncore, Medusa Do not consider exception as nasty things which want to break you programs.

Exceptions are you friend. Exceptions are a Good Thing. Exceptions are messengers which tell you that something's wrong, and what is wrong. Here's an example of defining an exception and a class say in myclass.

Yet, it is usefull because the exception itself is a message. You just need the win32all python module to access COM objects from within Python see http: Under Windows, ODBC provides an easy way to access almost any database.

It's not very fast, but it's ok. You need the win32all python module. You can also use fetchone or fetchmany n to fetch - respectively - one or n rows at once. On big datasets, I have quite bizarre and unregular data truncations on tables with a high number of columns. Is that a bug in ODBC, or in the SQL Server ODBC driver? I will have to investigate Under Windows, you can also use ADO Microsoft ActiveX Data Objects instead of ODBC to access databases.

The following code uses ADO COM objects to connect to a Microsoft SQL Server database, retreive and display a table. TinyWeb is a one-file webserver for Windows the exe is only 53 kb. It's fantastic for making instant webservers and share files. TinyWeb is also capable of serving CGI.

Trackforward - outbound postings - eichin@aqasesuyohaw.web.fc2.com

You should see " Hello, this is Python talking! If it's ok, you're done! Now you can make some nice CGI. If this does not work, make sure the path to python. Thus it's not appropriate for high-traffic production servers, but for a small LAN, it can be quite handy to serve CGI like this.

You will typically find your program as. Your program will run on any computer even if Python is not installed.

This also works for CGI. Note that if your program uses tkinter, there is a trick. This will greatly reduce file size. Python is provided with a code profiling module: It's rather easy to use.

As you can see, the profile module displays the precise filename, line and function name. This is precious information and will help you to spot the slowest parts of your programs. To speedup your Python program, there's nothing like optimizing or redesigning your algorithms. In case you think you can't do better, you can always use Psyco: Psyco is a Just-In-Time-like compiler for Python for Intel 80xcompatible processors.

It's very easy to use and provides x2 to x instant speed-up. This way, if psyco benefits of us binary options brokers that accepted installed, your program will run faster. If psyco is not available, your program will run as usual.

Do not use Psyco when debugging, profiling or tracing your code. You may get innacurate results and strange behaviours. I helped someone on a forum who wanted process a text file: He wanted to extract the text following "Two words" in all lines starting whith these 2 word. He had started writing a regular expression for this: Besides, string methods like findrfind or startwith are very fast, much faster than regular expressions.

Do not try to use regular expressions everywhere. Often a bunch of string work from home jobs memphis will do the job faster. Reverend is a free Bayesian module for Python. You can download it from http: You can train it on even more languages at the same time.

You can also train it to classify any kind of text. They are not necessary. This depends on which features of Tkinter your program will use. You can take the entire control of this process and write your own webserver in Python. Here is a simple webserver which say " Hello, world! While writing your own webserver can be fun, think twice before putting this into production. Gmail is neat, but what happens if you account disappears? Better safe than sorry: This baby can archive python optionparser callback example whole GMail box in a single standard mbox file which can be easily stored and imported into any email client.

Python optparse callback giving arguments to function - Stack Overflow

Run it, enter login and password, wait, and you have a yourusername. When using urllib or urllib2 to send HTTP requests, it default sends HTTP GET requests.

Sometime, you need to POSTeither because the remote form does not support GET, or you want to send a file, or you do not want the request parameters to appear in proxy logs or browser history. BeautifulSoup htmlSource for item in soup.

Traceback most recent call last: You made a mistake! Connect 'servername','login','password' for i in range 1,s. Execute 'SELECT clientid, clientName FROM clients' [0] while not recordset. QueryValueEx key, 'Download Directory' print value print valuetype.

Thu Jul 03 The dynamic link library tk Can't find a usable init. Read from a file: Never confuse data and it's representation on screen. If module not imported successfully, raise an error. The proxy address and port: Document type is Date: Thu, 23 Mar Start Excel and open the XLS file: Open filepath Save as CSV: Excel does not like loooooong lines.

Using CSS, you can even force the cell format text, numeric, etc. Please look in the log file. Unicode table to F 0 to Latin characters Unicode table to 00FF to Latin characters, including accented characters Unicode table to F to devanagari Unicode table to F to hangul jamo.

Transmitting a text alone is useless. This is the same for emails: Use -h for help. You used the --output option with value output.

AutoItSetOption "WinTitleMatchMode", 4 autoit. If can't instanciate, try to register COM control again: It should be http: Property x is read-only. Returns only the links URL. A list of urls strings.

aqasesuyohaw.web.fc2.com- Snyppets - Python snippets

Duplicates links are removed, links are sorted. Is there a "Next" link for next page of results? A list of colors in HTML notation eg. Import matplotlib and PIL import matplotlib, matplotlib. This functions removes the usless "white" space around an image. The image to crop. If the image is transparent, this parameters will be ignored. If the image has a transparency layer, use it. So we need to substract the "background" color from our image.

Count of different word: You can generate cover files this way: Write the CSS file: The image is saved in current directory. In case the image is not valid eg. If filename is not provided, a name will be automatically provided. None if the image is not available. Either Flickr has problem, or the website has changed.

I sometimes get this exception. HTTPServer '',MyHandler server. Simply enter your login and password, and all your emails will be downloaded from GMail and stored in a standard mbox file. This inclues inbox, archived and sent mails, whatever label you applied.

Spam is not downloaded. This mbox files can later on be opened with almost any email client eg. This notice may not be removed or altered from any source distribution. I'm a simple text file. We replace with a space. New logical stream 1, serial: Org libVorbis I 1.

Morcheeba - Dive Deep - 01 - Enjoy The Ride. No option 'duffy' in section: Great for a simple LAN music server. We will return the.

Return the music file with proper MIME type. Will simply return a ThreadingTCPServer '', PORTminiMusicServer print u"Music server ready at http: ThreadingTCPServer '', PORTwebDispatcher print u"Server listening at http: We wait for the worker to stop. I have the lock. Finished" def thread2 lock: I do not have to lock. Let's do something else.

The fewer threads the better. The fewer locks the better. The IP address in string format. None if not internet connection available. None if could not be determined. This work is licensed under a Creative Commons Attribution 2. Python Snyppets Snippets for the Python programming language.

博客频道 - aqasesuyohaw.web.fc2.com

Snyppets - Python snippets. Unicode table to F 0 to Latin characters. Unicode table to 00FF to Latin characters, including accented characters. Unicode table to F to devanagari. Unicode table to F to hangul jamo. The Python unicode string. Cropping a transparent image: Cropping a non-transparent image:

inserted by FC2 system