-
Replied To a Post in Python dictionary.
To fix your orginal code. def translate(): a = {"merry":"god", "christmas":"jul", "and":"och", "happy":"gott", "new":"nytt", "year":"år"} return a for k, v in translate().iteritems(): print k, v You need to practice more … -
Replied To a Post in returning a string that's 'n' characters long
A couple of ways. from __future__ import print_function def generate_n_chars(n, a): for i in range(n): print(a, end='') def generate_n_chars_1(n, a): result = '' for i in range(n): result += a … -
Replied To a Post in UnboundLocalError: local variable referenced before assigment:
Is this all of your code? There are missing several function definition here. You never use `return` without a function. Post all of you code and full `Traceback`. Or at … -
Replied To a Post in List Help!
With enumerate(). >>> mylist1 = [1,2,3] >>> mylist2 = ['a','b','c'] >>> for index, item in enumerate(mylist2, 2): ... mylist1.insert(index, item) ... >>> mylist1 [1, 2, 'a', 'b', 'c', 3] Flatten … -
Replied To a Post in iPython Notebook
A distribution such as [Anaconda](https://store.continuum.io/cshop/anaconda/) make it easy to run iPython notebook without thinking of dependencies. I aslo have [Miniconda](http://conda.pydata.org/miniconda.html) wish i run iPython notebook/Spyder for python 3.4 from. Anaconda … -
Replied To a Post in An example of a threading background decorator (Python)
A little look at [concurrent.futures](https://docs.python.org/dev/library/concurrent.futures.html) concurrent.futures has a minimalistic API for threading and multiprocessing. Only change one word to switch `ThreadPoolExecutor(threading)` and `ProcessPoolExecutor(multiprocessing)`. [concurrent.futures](https://pypi.python.org/pypi/futures) is backportet to Python 2.7 A … -
Replied To a Post in How to select a certain sequence in fibonocci?
wooee show that `range()` work fine,another good and pythonic way is to use a generator. If also use [itertools.islice()](https://docs.python.org/2/library/itertools.html#itertools.islice) can make it even more versatile. from itertools import islice def … -
Replied To a Post in arguments
Look at this [post](https://www.daniweb.com/software-development/python/threads/481966/optional-funtions#post2107767) -
Replied To a Post in Contents of web form to python script
> From what I can tell, the directory structure that works with Flask is this: Yes > How would I go about doing something where, if I type: Some stuff … -
Replied To a Post in Contents of web form to python script
As mention bye chriswelborn use [Flask](http://flask.pocoo.org/) or [Bottle](http://bottlepy.org/docs/dev/index.html). CGI is dead in Python after [PEP 3333](http://legacy.python.org/dev/peps/pep-3333/)(WSGI). Flask,Bottle is a layer above WSGI and 100% WSGI compliant. > You need some … -
Replied To a Post in Importing another class
> either I guess ungalcrys has left Python a long time ago. This is his only post over 4 year ago,look at dates. -
Replied To a Post in Help with Classes
--- -
Replied To a Post in Help with Classes
> If you really wanted it in list format you could do this to it: Yes i agree if that's really what BingityBongity want, but a plain list with no … -
Replied To a Post in Break up a sequence into groups of 3 elements
> Nice, but it shortens the list if the length is not a multiple of 3. Yes that's right,an other solution is to use map(). >>> mylist = [0, 1, … -
Replied To a Post in Break up a sequence into groups of 3 elements
>>> zip(*[iter(mylist)]*3) [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)] -
Replied To a Post in Generating Keyboard Presses
Setuptool can be found [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/#setuptools). Correct environment variable is `;C:\python33\;C:\python33\scripts\;` Look that's is correct by looking at [Path](http://www.nextofwindows.com/how-to-addedit-environment-variables-in-windows-7/). -
Replied To a Post in Generating Keyboard Presses
Use [PyUserInput](https://github.com/SavinaRoja/PyUserInput) Install [Pywin32](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32) and [Pyhook](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook) Install [pip](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip) Then do `pip install PyUserInput` from pykeyboard import PyKeyboard k = PyKeyboard() # pressing a key k.press_key('H') # which you then follow … -
Replied To a Post in XML file searching
In [34]: codeList = '''\ <ScanCode> <Code>Superman 12345</Code> <User>Clark kent</User> <DateTime></DateTime> <Comment/> <LineNumber></LineNumber> <SeqNumber></SeqNumber> </ScanCode>''' In [35]: import xml.etree.ElementTree as ET In [37]: xml = ET.fromstring(codeList) In [41]: xml.find('User').text Out[41]: … -
Replied To a Post in XML file searching
> the pring codelist prints out the cancodes/scancode/code section to show that it has fount something. Is it in "xml" foramt? Post a sample. If i iterate over codelist(`for el … -
Replied To a Post in lamda expression to match beginning of line with any digit
Why lambda expression? It can make code less readable. > All you should need to do is import string and apply in to your string's first character, and string.digits, and … -
Replied To a Post in XML file searching
codeList = root.findall(".//ScanCodes/ScanCode/Code") print codeList What dos "print codelist" output. So here as a demo i use find() to find "value" and "text" in [1]: xml = '''\ <foo> <bar … -
Replied To a Post in Linking python with MySQL
[MySQLdb](https://pypi.python.org/pypi/MySQL-python/1.2.5) or [PyMySQL](https://github.com/PyMySQL/PyMySQL) -
Replied To a Post in filtering normal readable text from junk
Post link and what you what out. -
Replied To a Post in Looking for numbers in file name
That 100 line long fileBreak function is really not good at all. You should split it up,functions should be around 10-15 lines. Do not try to do to much in … -
Replied To a Post in Looking for numbers in file name
> it does for the files but i jsut got told they arent files but subfolders that have the numbers in the names which makes this so much more confussing … -
Replied To a Post in Nonetype error
You really shouldn't be be using CGI. Did you read me answer in you other [post](http://www.daniweb.com/software-development/python/threads/481910/python-and-localhost)? You never call calc function,line 18 i think should be inside calc function. To … -
Replied To a Post in builtins.UnicodeDecodeError:
> The files I'm working on are all binary files, .mp3, .flac, & .wav. Does that help at all? Sure you have to look at specification for these file types. … -
Replied To a Post in Optional Funtions
Yes is called default argument. def say(msg, arg='something'): print 'first argument <{}> default argument <{}>'.format(msg, arg) >>> say('hello') first argument <hello> default argument <something> >>> say('hello', 'world') first argument <hello> … -
Replied To a Post in Python and localhost
Cgi is pretty much dead in Python,and that's is very posetive. Python community did make an all Python soution [PEP 3333](http://legacy.python.org/dev/peps/pep-3333/) So this is called [WSGI](http://wsgi.readthedocs.org/en/latest/)(Web Server Gateway Interface),and is … -
Replied To a Post in Word Frequency in a Text String (Python)
Stefan stop post your code in 8 years old `Code Snippets` post. Yes Python has moved on,and your soultion is not better at all. >>> from collections import Counter >>> … -
Replied To a Post in Filtering certain words in a list in Python
Start by testing stuff out in interactive interpreter. >>> lst = ['This', 'is' 'some', 'test', 'of', 'someting'] >>> lst[0] 'This' >>> len(lst[0]) 4 So useful for finding 4 letters word. … -
Replied To a Post in Save text area to selected file
Re upload your code with working indentation. -
Replied To a Post in how to split file downlaod to ranges using requests package
Do you mean download a file in chunk(spilt it up) so it dos not use so much memory? Something like a do in this [post](http://www.daniweb.com/software-development/python/threads/478404/parse-large-one-line-text-file#post2089945). -
Replied To a Post in builtins.UnicodeDecodeError:
I think Gribouillis has postet some about unicode in Python 3 in your previous posts. Can take a little more about this,for unicode was a big change in Python 3. … -
Replied To a Post in Splitting a filename
> And there you go, you just mentioned another way of solving the problem. There are several ways to the market in this case. Yes there are severals ways,i was … -
Replied To a Post in python program installer
> pyinstaller to make an executable, wouldn't that eliminate the need for the python to be installed on the system? Yes and there are more [tool](http://docs.python-guide.org/en/latest/shipping/freezing/),a GUI [tool](https://code.google.com/p/gui2exe/) for many … -
Replied To a Post in Accessing a Hindi Text file, counting the number of occurrences of words
> and now please tell me the default path, that the command codecs.open() makes use of. or tell me the path of the file u saved in.. ) `codecs.open()` dos … -
Replied To a Post in Accessing a Hindi Text file, counting the number of occurrences of words
I get a count of 4 with conted in your last post,i save your content as *UTF-8* and read it in same way. #Python 2.7 import codecs with codecs.open('test_hindi.txt', encoding='utf-8') … -
Replied To a Post in ImportError: No Module Named ElementTree
Import is. >>> import xml.etree.ElementTree as ET >>> ET.VERSION '1.3.0' And you should not name file `elementtree.py`,it shall not be in desktop folder. This is a file in Pyhon library. … -
Replied To a Post in Python Help!
> Hey ... sorry I missed that ... is that why you 'down-voted' ? It was not me as downvoted you :) -
Replied To a Post in Python Help!
The error message is very clear,Python can not find "sample.txt" in that path. with open('C:/Users/jolie_tia/Documents/sample.txt') as f: print f.name '''Output--> Message File Name Line Position Traceback <module> <module4> 1 IOError: … -
Replied To a Post in Question from a beginner learning Python
You have convert all input to integers,so answer(ans) is also an integer. Can look at some improvement. num1 = int(raw_input("Enter an integer")) num2 = int(raw_input("Enter a second integer")) num3 = … -
Replied To a Post in Project for beginners loop through names
def lst_corrector(lst, index_vaule): value_change = raw_input('Enter correct value: ') for index, item in enumerate(lst): if index == index_to_change: lst[index] = value_change return lst #Error should be car lst = ['boat', … -
Replied To a Post in Project for beginners spellchecker
Dont use `list` and `dict` as variable names,words are reseverd bye Python. To clean it up. my_file = open("words.txt") lst = [] #Outside the loop for word in my_file: word … -
Replied To a Post in Can't convert 'int' object to str implicitly
Slice it out can be another option. with open('06 Rooster.mp3', 'rb') as f: f.seek(-128,2) tag_content = f.read(128) title = tag_content[3:33] print title # Rooster You do know that there are … -
Replied To a Post in Python challenge
> by having a capturing group ([a-z]), I still got 175 matches and they were just single letters Did you place `[^A-Z]` as i told you? Then it should look … -
Replied To a Post in Python challenge
> I have tried a written a code like so re.findall(r'[A-Z]{3}[a-z][A-Z]{3}',string) to find the solution for this python challenge Add [^A-Z] in each end. [^A-Z] # any character except a … -
Replied To a Post in Command line arguments python
Take a look at [Click](http://click.pocoo.org/) from the creator of [Flask](http://flask.pocoo.org/) Armin Ronacher. -
Replied To a Post in Regular expressions from python challenge
Hint. >>> import re >>> data = '''(*^+*]$]+@+*_##)&)^(@$^]e@][#&)(''' >>> re.findall(r'[a-z]', data) ['e'] -
Replied To a Post in Python Challenges
Here a version of `iglob`,that can take multiple file extensions. #iter_glob from glob import iglob from itertools import chain import os, sys def iter_glob(path=None, *args): '''A iglob version that return …
The End.