3,386 Posted Topics
Re: 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! | |
Re: 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 … | |
Re: 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] | |
Re: And for counting from collections module defaultdict(int) (should be capilized but is not) or Counter for latest versions. | |
Re: You are writing assignment = instead of comparision == in if statement. | |
Re: 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 … | |
Re: And where you need it and what is your Python code for it? | |
Re: Then you should mark this thread solved. You could also consider posting your explanation of what the solution was. | |
Re: What kind of error are you getting from your code. Post also sample input with your code and correct output expected. | |
Re: compare with others, learn and apply lesson to your own code: [url]http://www.daniweb.com/forums/post135044.html#post135044[/url] | |
Re: 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] | |
Re: 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] | |
| |
Re: Tkinter has graphical way to do file selection which is less OS dependent. For data we have shelve, pickle and json modules. | |
Re: 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 … | |
![]() | Re: If pylab has not it, I remember that numpy has function for classifying values. ![]() |
Re: 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 … | |
Re: 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 … | |
Re: Gribouillis want to stop counter wrap arround to stop program destroying files. Rename = move in Linux systems. Good thinking. | |
Re: 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. | |
Re: 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. | |
Re: Maybe this would help you: [url]http://stackoverflow.com/questions/811548/sqlite-and-python-return-a-dictionary-using-fetchone[/url] | |
Re: Can you give example of any code running in 2.5 not running in 2.71 or 2.6.6? | |
Re: except IncompleteRead or maybe leave out the length from read if possible. Normaly you would not like to read incomplete page. | |
Re: 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] | |
Re: 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, … | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: I do not understand how you process information. For me looks that you do not process or save received information. | |
Re: 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. | |
Re: I for one am offering programming and Python e-tutoring in my company The Bentley offering looks promising to integrate with. | |
Re: [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 … | |
Re: [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() … | |
Re: 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? | |
Re: Why are you printing the file handle I thought you wanted to read what is inside the file? | |
Re: It would be appreciated if you would read and tried to follow the naming rules of PEP8. | |
Re: Using dictionaries with their very well optimized hash functiones and flexibility often leads to more clear and efficient code. | |
Re: 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. | |
Re: what have you tried to do? | |
Re: Strings are sorted first by their first letter so 'ab' < 'c' or '10'<'3' | |
Re: 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 … | |
Re: You have not posted how you are actually using the classes. | |
Re: from pyclutter page looks that you should use pyGObject instead. | |
Re: 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 … | |
Re: 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 |
The End.