This is one small snippet of after event usage. You could express if you find this kind of simple code to be usefull as snippet. Notice also vegaseat's sticky message threads in begining of Python forum in addition to code snippets.

Member Avatar
Member Avatar
+0 forum 4

Sometimes we want to not split by every space character, but we want to split only on those outside of brackets and quotes. This way we can have for example quoted string as single argument for command. EDIT: 1. Added hierarchical nesting of same kind of brackets. 2. Bunching multiple separators as single separator, None as general whitespace separator Test output: ---------------------------------------------------------------------------------------------------------------------------------- Hello, (Tony 'pyTony' Jarkko Veijalainen) {'This 'is' quoted' Great to "split" this} split "Also Quoted part" [test test] end Hello, (Tony 'pyTony' Jarkko Veijalainen) {'This 'is' quoted' Great to "split" this} split "Also Quoted part" [test test] end …

Member Avatar
Member Avatar
+1 forum 2

Python helps in real life situation to automate things. This program helps you to prep up your kids ability to go over/under ten, which is essential not only by itself, but also when calculating with bigger numbers. Program is not any special, but shows how useful Python can be in real life situations.

Member Avatar
Member Avatar
+0 forum 2

Here some old fashioned line input routine, better idea nowadays would be to use GUI input box with real editing. Anyway, it is quite simple with Python to do this basic routine for terminal based program.

Member Avatar
Member Avatar
+4 forum 3

I did code for challenge that I saw posted for C# by deceptikon: http://www.daniweb.com/software-development/csharp/threads/479304/coding-challenge-string-to-date Here it is. Of course normally the code would be without prints and put in function, but this is enough for now for me. There could also be normalization from '/' separated form not producing ambiguous form, checking for single digit month/day. Notice that reversed order of slice assignement is a must as well as variable holding the original length or that length's format!

Member Avatar
+1 forum 0

I [saw interesting problem](http://www.daniweb.com/software-development/legacy-languages/threads/478323/prolog) of generating spiral of numbers and realized I could reuse [my code for rotation](http://www.daniweb.com/software-development/python/code/371536/rotate-sequences-left-or-right) I posted earlier.

Member Avatar
+3 forum 0

Here is simple text file example for beginners, using try..except for reading old content as it may not yet exist.

Member Avatar
Member Avatar
+1 forum 6

There is free tools to do the same, but I was curious to see what it takes to make one myself. For info see: [url]http://en.wikipedia.org/wiki/LC-3[/url]

Member Avatar
Member Avatar
+5 forum 10

Here little debugged version of my calculator posted earlier in GUI calculator thread. I prepared it after listening that their teacher did more limited calculator in around 150 lines of code with their graphics module. This is 115 lines without empty lines and comment lines [CODE]>>> li=[i for i in open('SimplistiCalc.pyw') ... if i.strip() and not i.strip().startswith('#')] >>> len(li) 115 >>>[/CODE] Save attached gifs to same directory as the code. Comments welcome!

Member Avatar
Member Avatar
+1 forum 9

Here is exercise in error handling, while looping and for looping with itertools.chain. It is also exercise of functions not letting user to go without giving proper input. I call them to myself 'jail functions'. Here you could add as an exercise breaking out of loop and continuing until user request to quit. The code works in both Python2 and Python3 with Python2 input overwritten to be raw_input.

Member Avatar
Member Avatar
+0 forum 1

You can fix one parameter of function call by calling underlying method of fixed parameter instead of using functools.partial or lambda statement.

Member Avatar
Member Avatar
+1 forum 2

Here is my celebration post for entering level 3 in Project Euler. Again I left in my debug prints. I am in process of adapting myself to new .format style of formatting. I have commented out the prints though to get visible the running time of the functions own action. It is not doing half bad actually: J:\test\Project Euler>\python27\python -m timeit "import euler61" "euler61.euler61()" 100 loops, best of 3: 2.5 msec per loop That is faster than the printing of the result to console with newline. Of course, my generator expression is anything but PEP8 compliant in it's simplicity, but …

Member Avatar
Member Avatar
+0 forum 4

![circuit](/attachments/small/2/circuit.jpg "align-right") Here is a version in Python of program from classic Lisp book (see http://www.daniweb.com/software-development/legacy-languages/code/446235/simple-scheme-functions-for-finding-impedance-for-norvigs-implementation for the details) for calculating impedance of a circuit. (Example circuit with 1MOhm like in the book's code not like in diagram)

Member Avatar
+0 forum 0

![Lisp001](/attachments/small/2/Lisp001.jpg "align-left") ![Lisp002](/attachments/small/2/Lisp002.jpg "align-right") I did translation to minimal Scheme implementation of Norvig written in Python (http://www.daniweb.com/software-development/python/threads/359370/norvig-an-even-better-lisp-interpreter-in-python) of the impedance code defined in classic book **Lisp by *Patric Henry Winston* and *Berthold Klaus Paul Horn*** from year 1981 (first computer book I ever bought). Errata: diagram has 10 MOhm when the code listed has 1 MOhm. I could not get eval to see the omega given as parameter to impedance in l and r functions so I had to do define in caller before invoking the function instead. If anybody knows the way to do it in Scheme, I would …

Member Avatar
+0 forum 0

Here is code, which you can play with before installing and using the [superior blist package from pypi](http://pypi.python.org/pypi/blist/). I did it as therapy after doing programming test answer using zillion of setters and getters. Motivation is basically to show why you should use properties after you need them and attribute access before that. The function of before and after links is exchangable, so you can do reversing of directions of double linked list by just sweeping through list and toggling the flag. If that quite a hackish feature would not be there we would not need to use property. Here …

Member Avatar
+0 forum 0

Now that MITx first test is over, I got feeling that this one task requested for generate and test solution is begging also for less efficient recursive solution as it is so simple. Here it is! Single liner aproved by the released grader! If you wander if you are able to buy exactly n nuggets by boxes of 6, 9 or 20 nuggets each, it tells the answer. It does not tell you how heavy your shopping bags would be and how many geeks you need to eat them ;) This recursive version can not deal with 1000000 nuggets (using …

Member Avatar
+0 forum 0

Here improved example based on MITx course of using the bisection method for root finding.

Member Avatar
+0 forum 0

Here is slow brute force way to find the largest palindromic product of three digit integers. You could do loop and break out of it if you go under the smaller number (the second one) of best solution found so far to be more efficient etc.

Member Avatar
Member Avatar
+0 forum 3

There was discussion thread http://www.daniweb.com/software-development/python/threads/424953/polynomial-division for class based implementation for polynomials, and I developed a version utilizing the magic methods to enable operation with normal arithmetic operation. I only inherited sequence structure from list type. Interoperability with scalar types is not implemented to avoid too complicated type checks of the arithmetic operations. **Division will be added** when the OP has made his own solution of it ready. Tests are continued to be run and I will update the code with bug fixes if and when I find any. I have done informal tests but not yet exhaustive ones. Multiplying by …

Member Avatar
Member Avatar
+1 forum 9

As in C++ was some question about speed of simple hard disk based lookup, here is a version of unscramble program completely HD based lookup, which gives all possible candidate words for multiword anagram. Program is not sensitive for case of words but does not ignore special characters like ' or space, but sub-word condition means that it is possible to input any number of special characters without disturbance. For example: [CODE]Possible multiword anagram candidate words To quit enter empty line Give word: Tony Veijalainen a ye to on no it in at an yon yet yen yea voe vie …

Member Avatar
Member Avatar
+0 forum 4

Because of [C++ code snippets not dealing with multiple +-](http://www.daniweb.com/posts/jump/1829367) in sequence (or even negative number) in expressions, I post this, as it is so much easier for me than C/C++. EDIT: Fixed signs together with '(' issues and '+' at beginning removing without lstrip, removed separate now unused '(' branch from if. Changed name of prev to plusminus.

Member Avatar
+0 forum 0

This is bit funny code as you can first read from this excellent response: http://www.daniweb.com/software-development/python/threads/427341/custom-types-in-a-simple-way#post1828718 why should you not use it, even it maybe feels useful. Anyway I got curious to see how type signature could be implemented, even using it would generally just be stupid way of slowing down your code. But like mountain climbers tell about why they climb the mountain: "Because it is there". So here this un-Pythonic do not trust user as responsible adult code is. Maybe those hasattrs could have been try...except, but as it is unpythonic any case, who cares... Also using recursion for …

Member Avatar
+0 forum 0

Here you see how one could use recursion together with generators for (inefficient) permutations generator. It is kind of interesting to know how one can do it recursively (of course there exist many ways). Anyway this snippet demonstrates how you can use recursive generator call to feed a for statement. If you want usefull use of recursive generator, see my 11.11.11 11:11:11 Code Snippet post of [full multiword anagram program](http://www.daniweb.com/software-development/python/code/365540/simple-multiword-anagram-candidate-words).

Member Avatar
+0 forum 0

I googled little around for correct way to not reinventing of the wheel for expression evaluation (even I had done some simple evaluation check for my [Tkinter calculator snippet](http://www.daniweb.com/software-development/python/code/282548/simple-calculator) earlier). After getting totally upset with [this example](http://www.bestcode.com/html/evaluate_math_expressions_pyth.html), I made this with some struggles with `__builtins__` globals parameter of eval. First I kept the dictionary of variables approach, then I turned to keyword parameters, the format is so much nicer. To put some topping, I put `__call__` also as synonym for evaluation. That means you can call the class as functions and give any values of variables as keyword parameters. See …

Member Avatar
+0 forum 0

Sometimes we want to tackle some problem specifying properties of sequence of numbers consisting the integer. Then it is usefull to have function to join many integers to make a long integer. Most efficient way for tight loops is to stay in integers domain and not go through the string representation. Inspired by C++ question and my answer to it: http://www.daniweb.com/software-development/cpp/threads/425472/how-concatenate-number-in-c#post1819908

Member Avatar
Member Avatar
+0 forum 3

Finding efficiently primes, whose begining numbers are also primes. See the thread http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c in C++ forum for discussion on topic.

Member Avatar
+1 forum 0

We can run Python2 script in most simple cases if we just use the 2to3.py script found in recent Python versions: F:\Python27\Tools\Scripts>copy \test\output_window_tk.py \test\output_window_tk2.py 1 tiedosto(a) on kopioitu. F:\Python27\Tools\Scripts>2to3.py -w \test\output_window_tk.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: Refactored \test\output_window_tk.py --- \test\output_window_tk.py (original) +++ \test\output_window_tk.py (refactored) @@ -1,5 +1,5 @@ -from ScrolledText import ScrolledText -from Tkinter import BOTH, YES, END +from tkinter.scrolledtext import ScrolledText +from tkinter import BOTH, YES, END fn = 'f:/Python27/setuptools-wininst.log' mywin = ScrolledText() RefactoringTool: Files that were modified: RefactoringTool: \test\output_window_tk.py Here we backed …

Member Avatar
+0 forum 0

Gribouillis has allready posted code similar to this in his snippets, but here version for input suitable for for expressions, generators and list comprehensions. Need to add robustness by some try...except blocks for real world use.

Member Avatar
Member Avatar
+0 forum 10

This came up, maybe it is usefull to somebody. Later I plan to do a managing context interface to `with`statement for this.

Member Avatar
Member Avatar
+0 forum 2

Here slightly edited code from one of my earliest posts to DaniWeb. Limitted by recursion limit of Python as it uses recursion, but interesting for me.

Member Avatar
Member Avatar
+0 forum 2

The End.