3,386 Posted Topics

Member Avatar for Vi3tkevin

Your small start has not correct syntax. Push the (code) button befor pasting your code. Show little more effort and others can help you out in confusions and misunderstandings. Others can not however learn instead of you. Good luck!

Member Avatar for TrustyTony
0
143
Member Avatar for pythonbegin

listofitems = [1,2,3,4,0.5,0.6] listofitems2 = [a,b,c,d,e,f] listofitems3 = [a1,s1,d3,4f,f4] for arg1 in listofitems: for arg2 in listofitems2: for arg3 in listofitems3: subprocess.call("Rscript script.R --args arg1 arg2", shell=True) so that it can take each item from each list and iterate over it. > Does this make sense? Makes more sense at …

Member Avatar for TrustyTony
0
5K
Member Avatar for toritza

You can generate list of list of distances to every other city by list comprehension or for loop using Pythagoras triangle formula, if exactness is not needed, else you need to find about [URL="http://en.wikipedia.org/wiki/Haversine_formula"]calculating distances on surface of ball of 40000 km perimeter.[/URL]

Member Avatar for Gribouillis
0
2K
Member Avatar for jamseyjames

And for counting from collections module defaultdict(int) (should be capilized but is not) or Counter for latest versions.

Member Avatar for richieking
0
83
Member Avatar for kinto
Member Avatar for woooee
0
170
Member Avatar for Rockpile

input's meaning is same as before raw_input in Python 2. This is good thing, as it is not good idea to ever use input in Python 2. I myself usually do this like in the beginning of this simple program (split emulator to demonstrate itertools.groupby) to get programs run in …

Member Avatar for TrustyTony
0
286
Member Avatar for rssk
Member Avatar for BirdaoGwra

Then you should mark this thread solved. You could also consider posting your explanation of what the solution was.

Member Avatar for BirdaoGwra
0
296
Member Avatar for nidhisajan

What kind of error are you getting from your code. Post also sample input with your code and correct output expected.

Member Avatar for TrustyTony
0
29
Member Avatar for canyvr

compare with others, learn and apply lesson to your own code: [url]http://www.daniweb.com/forums/post135044.html#post135044[/url]

Member Avatar for woooee
0
128
Member Avatar for hughesadam_87

Simpler but potentialy unsafe is to write out lines starting with number: [code]for line in infile: if line[0].isdigit(): outfile.write(line)[/code]

Member Avatar for hughesadam_87
0
151
Member Avatar for Thristan_

In single directory not descending in sub dirs: [CODE]import os start = 'label' for fn in (f for f in os.listdir(os.curdir) if f.startswith(start) and os.path.isfile(f)): print(fn) [/CODE]

Member Avatar for richieking
0
421
Member Avatar for yeleek
Member Avatar for hughesadam_87

Tkinter has graphical way to do file selection which is less OS dependent. For data we have shelve, pickle and json modules.

Member Avatar for Gribouillis
0
161
Member Avatar for Celtrix

Traditional way to do this is by temporary variable, because we need the old value of b in two formulas on the right side. Let's call the temporary variable new_b: [CODE]a,b=0,1 while b < 100: print b new_b = a + b a = b b = new_b [/CODE] alternatively …

Member Avatar for Celtrix
0
110
Member Avatar for tottletj
Member Avatar for tottletj
0
85
Member Avatar for doomas10

You are doing split multiple times to lines. Better way would be to to open the file in with statement, which garantees closing of the file automatically, split each line once to variable and do the slicing from there. If files are small your code is 'good enough' Same way …

Member Avatar for doomas10
0
211
Member Avatar for flebber

Start small. First learn to split and do fixed change to file name. Just print the result. Then change the file name to be element from fixed list of file names using for loop... This is bottom up implementation. Usually it is easier to design top down and implement bottom …

Member Avatar for snippsat
0
2K
Member Avatar for maniac00

Gribouillis want to stop counter wrap arround to stop program destroying files. Rename = move in Linux systems. Good thinking.

Member Avatar for Gribouillis
0
123
Member Avatar for stefh

Use prints to console to debug. You can put condition [code]if ligne:[/code]or[code]if ligne is not None:[/code] I usualy get this error when I forget that append does not return value in Python but has side effects.

Member Avatar for stefh
0
666
Member Avatar for Thropian

Common idiom is to construct fresh string using slicing. That is assigned to old variable if it is not needed anymore. This can be further developed by doing the string generation in generator expression we can pass to join method producing suitably joined new string.

Member Avatar for TrustyTony
0
118
Member Avatar for Greyhelm

Maybe this would help you: [url]http://stackoverflow.com/questions/811548/sqlite-and-python-return-a-dictionary-using-fetchone[/url]

Member Avatar for richieking
0
5K
Member Avatar for tcl76

Can you give example of any code running in 2.5 not running in 2.71 or 2.6.6?

Member Avatar for TrustyTony
0
3K
Member Avatar for zizuno

except IncompleteRead or maybe leave out the length from read if possible. Normaly you would not like to read incomplete page.

Member Avatar for TrustyTony
0
350
Member Avatar for kikuolen

If you use version 3, BTW official release of 3.2 has just been released. This should help you: [url]http://docs.python.org/py3k/tutorial/index.html[/url]

Member Avatar for TrustyTony
0
45
Member Avatar for wilko1995

Maybe trace prints from this would clarify?: [CODE]def hanoi(n, a='A', b='B', c='C'): """ move n discs from a to c using b as middle """ indent = ' '*(10-n) print indent+'hanoi(%i, %s, %s, %s)' % (n,a,b,c) if n == 0: return hanoi(n-1, a, c, b) print indent,a, '->', c hanoi(n-1, …

Member Avatar for TrustyTony
0
117
Member Avatar for novice20

I for one, did not get any error or doubles from your code and it looks almost same as code in Python documentation: [CODE] import logging # create logger logger = logging.getLogger("simple_example") logger.setLevel(logging.DEBUG) # create console handler and set level to debug ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) # create formatter formatter …

Member Avatar for novice20
0
103
Member Avatar for computerstudent

And now at the end, the thing griswolf left out. It is example of power of Python that the thing you wanted requires not one line but [B]5 characters[/B][CODE][::3][/CODE] [CODE]>>> raw_input()[::3] Superman 'Sea' [/CODE] Actually this is not so relevant, I write it just for later, when you maybe need …

Member Avatar for TrustyTony
0
156
Member Avatar for canyvr

you should check only half way of the word discarding non-alphabet letters in multiword case. Your print should say palindrome. There is also simple way of checking if word is equal to it reversed.

Member Avatar for canyvr
0
157
Member Avatar for hailsontherocks
Member Avatar for paramaster

To sort the numbers in their normal meaning -> I deduce you have them as strings now? I recommend you to learn test based programming: make list of calls to your final function and what should be result of these test cases: [url]http://diveintopython.org/unit_testing/index.html[/url] Maybe this is of use, but probably …

Member Avatar for TrustyTony
0
106
Member Avatar for iwanttolearnc

For me it look like you can only write to a file the information and update from there. Only need to check for method of forcing a element to refresh regularly. This I found by quick Googling:[QUOTE] [URL="http://www.htmlgoodies.com/tutorials/getting_started/article.php/3479551/Reloading-The-Page.htm"]Reload All By Itself[/URL] This one's nice and easy. I'll give you the …

Member Avatar for iwanttolearnc
0
180
Member Avatar for l00kit

I do not understand how you process information. For me looks that you do not process or save received information.

Member Avatar for l00kit
0
254
Member Avatar for ksmakkapawee

You can not separate the word synonyms as they are mixed together. Of course you can hard wire lengths, but the synonyms should be split in groups. Then it is simple to zip them together and make dictionary.

Member Avatar for richieking
0
128
Member Avatar for Viasur

I for one am offering programming and Python e-tutoring in my company The Bentley offering looks promising to integrate with.

Member Avatar for richieking
0
147
Member Avatar for people people

[CODE]>>> dice_num = 9 >>> available = set(range(1, 1+dice_num)) >>> remove = raw_input('Give comma separated values: ') Give comma separated values: 3,5,1 >>> left_over = available - set(int(r) for r in remove.strip().split(',')) >>> left_over set([2, 4, 6, 7, 8, 9]) >>> remove = raw_input('Give comma separated values: ') Give comma …

Member Avatar for TrustyTony
0
128
Member Avatar for kinto

[QUOTE=kinto;1476758]Hello, I am stuck on how I have pass function arguments to the main method of my program. Here is my code: [CODE]network = [] def populateArray(): file = open('C:\\My Documents\\route.txt', 'r') for line in file: network.append(line) print "Network = " print network def main(): if __name__ == "__main__": main() …

Member Avatar for richieking
-1
265
Member Avatar for nosehat

It is possible, but 99 % not recommended. You should anyway backup the old file. Only if file should have dynamic content changing all the time it makes sense. But then why are you not using database?

Member Avatar for richieking
0
4K
Member Avatar for rawrxiv

Why are you printing the file handle I thought you wanted to read what is inside the file?

Member Avatar for richieking
0
144
Member Avatar for HelloPeople1

It would be appreciated if you would read and tried to follow the naming rules of PEP8.

Member Avatar for slate
0
112
Member Avatar for LoveMyPadres

Using dictionaries with their very well optimized hash functiones and flexibility often leads to more clear and efficient code.

Member Avatar for TrustyTony
0
194
Member Avatar for Ghostenshell

You only need to check if reversed string equals the normal one. To use stack and queue you can do comparision until first failure during reading back. Should not take more than 10 lines of code.

Member Avatar for Ghostenshell
0
2K
Member Avatar for HelloPeople1
Member Avatar for needsHelp!
Member Avatar for zizuno

Strings are sorted first by their first letter so 'ab' < 'c' or '10'<'3'

Member Avatar for zizuno
0
161
Member Avatar for da10x

Must say that I am lost. I would have made game with simple list of lists or strings and list of player locations. This is not my idea of readable and maintainable 'obvious' code Python is all about. I thought this game is played in simple square board of 9x9 …

Member Avatar for richieking
0
1K
Member Avatar for colts18
Member Avatar for TrustyTony
0
179
Member Avatar for woofers
Member Avatar for TrustyTony
0
259
Member Avatar for tcl76

Not so simple, but here is my solution based on simplified grouper as I used in my Sudoku post resently. More complete solution for grouping can be found in manual of itertools, using izip_longest. [CODE]def grouper(n, iterable): return zip(*((iter(iterable),) * n)) data = """cell Bit 0 1 1 X 2 …

Member Avatar for tcl76
0
249
Member Avatar for hkus10

You should put code-tags to keep the white space in your program. Even with reply the white space is not there. After fixing indention and trying to run the code including `import sys` I got error File "J:/python27/loop_problem.py", line 4, in <module> lines = sys.stdin.readlines() AttributeError: readlines

Member Avatar for woooee
0
102

The End.