3,386 Posted Topics
Re: Command line arguments you can access like normal list, just import sys and then access sys.argv, element 0 is the name of program, usually you process parameter is sys.argv[1:] part. [CODE]import sys print 'Parameters are:' for item in sys.argv: print item [/CODE] You run command from command window with parameters: … | |
Re: Why don't use simply: [CODE]test = [ ["x" for x in range(5)] for y in range (5) ] for y in test: print " ".join(y) [/CODE] Which can also be written as: [CODE]test = [ ["x" for x in range(5)] for y in range (5) ] print "\n".join([" ".join(y) for … | |
Re: to continue from vegaseat's hint: ...and you must deal with punctuation being put together with previous/following word. | |
Re: Consider which of next words must be replaced if 'of' is in word list: [CODE]'''off shore switch off often "of course" of.'''[/CODE] | |
Re: How about working with the 32 bit binary real representation, I posted conversion functions with IP number strings and real binary numbers as Code Snipet. Also you can prepare real binary mask for subnets. | |
Re: print each element in for loop which is inside other loop to do the sides.Finish with bottom lines. Can you assume one number values or should you check for maximum length of numbers for the grid? If you must check, find max of len(str(numbers))) in each element and max of … | |
Re: I would make it little clearer, what is logic of numbers and to make the subsquare thick lines, like original (for bigger squares, just change [ICODE]sq = 50[/ICODE] line) [CODE]# using the Tkinter canvas to # draw a line from coordinates x1,y1 to x2,y2 # create_line(x1, y1, x2, y2, width=1, … | |
Re: Like this for example (this example destroys the content of bitVal, so it should be for example function parameter or copy of one element of array) [CODE]bitVal = 0x01F ## takes Truth values from lsb to msb (least significant bit to most siginificant) while bitVal>0: if bitVal & 1:print True … | |
This code was in discussion of getting numeric input to Python. This function returns the zero-stripped, normalized string form the input string if it is correct, False truth value otherwise (it can not be mixed with number 0 as accepted '0' are returned as string '0'). If string passes the … | |
Re: Check out my ball moving algorithm, you can speed it up, if you transform it recursive from destination expanding neighbours until whole grid is covered and then do the final iterations of the algorithm on whole grid. [url]http://www.daniweb.com/forums/post1202455.html#post1202455[/url] To calculate distance on 1, consider 0 wall, and vice versa. | |
Re: You are not saving this data nowhere: [CODE]parser.feed(urlopen(url).read()) [/CODE] Please continue your threads if you have question from the same program! Cheers, Tony | |
Re: [url]http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html[/url] 10.5.6 505 HTTP Version Not Supported The server does not support, or refuses to support, the HTTP protocol version that was used in the request message. The server is indicating that it is unable or unwilling to complete the request using the same major version as the client, as … | |
![]() | Re: Any help from this? [url]http://old.nabble.com/Iterating-backwards-td14760782.html[/url] ![]() |
Re: Simple googling braught me this among others: [url]http://developer-resource.blogspot.com/2008/06/python-and-cuda.html[/url] | |
Re: Incorrect: [CODE]>> string = 'this is a test string' >>> string[:-10] 'this is a t' >>> ## right way >>> string[-10:] 'est string' >>> [/CODE] | |
Re: Set pythonpath environment variable to point to location of the cTurtle. | |
Edit/delete button (during 30 min after post) seems to have gotten problems after site change. It doubles the post instead of editing it and does not still allow cancelling the post. | |
Re: This question was asked already in forum, and I gave answer. Check old posts. But now I know shorter answer use [CODE]lines = open( 'sta1214.txt', "r" ).readlines()[::2][/CODE] (every 2 starting from beginning) and save lines to file. | |
Re: Do you mean how to change the text explanation in the label or how to create an Entry or Text widget for entering information by the user? | |
Re: You must add .split(eol) or do .partition(eol) by some end of line tag or '\n' according to your need. | |
Re: Yes. You just check the lowercase input with 'quit'. Even easier is to quit by '' empty line as it acts as False in if statement. How ever it is easy to give aksidentaly. | |
Here is way to put easily editable layout for input fields with standard look and collect the text variables to list for use. | |
Re: Global varible 'hit' which is user input is string and can not use as function. I do not understand your program. I can not find the deck of cards, dealing. Picture cards seem not to have value 10. I also do not see handling of ace as 1 or 10 … | |
Re: (not year%4 and year%100 or not year%400) and True 4 divides year (divides -> 0 = False -> not False = True) same time 100 does not divide year (anything but 0 is True) but if 400 divides the year it is OK ( divides -> 0 = False -> … | |
Re: Looks promising, BearofNH, I will study that code for myself. If you want to go the DIY way, maybe you can check up my histogram program ([url]http://www.daniweb.com/forums/post1183655.html#post1183655[/url]) with turtle graphics (kind of cute, but probably not the most efficient way) or put the objects in Tkinter Canvas proper way, even … | |
Re: For flaging tk has tags have you considered those? | |
Re: Here is some ways, first is to overcome too long lines, second to save typing. The second is not so useful maybe as you think, because Python is using byte code internally and then for speed for example the length of text does not matter so much. I only give … | |
Re: Here is for starters filter to read in to list the numbers, the newline characters are still in place. This filter disregards the *END* tag and only reads lines with exactly 15 number values on line without any other information [CODE] def fifteennumbers(a): sep=[x for x in a if not … | |
Re: It was tough to understand your code so I almost rewrote it to my way, this program output indented directorys marked with newline and *s and walks subdirectorys with more indention recursively. This is nice place to use recursion in my opinion. [CODE]#!c:/Python31/python.exe -u import os def mywalk(path,depth=0): if path.startswith('.'): … | |
Re: Neat coding vegaseat: [CODE] first, last, score1, score2, score3 = line.split(',')[/CODE] | |
Re: How about [CODE]import os from Tkinter import * import tkFileDialog class App(Frame): def createWidgets(self): self.grid() self.lbspace = Label(self, text="") self.lbspace.grid(row=0,column=0) self.lbfirstName = Label(self, text="First Name:", font=("Calibri", 12)) self.lbfirstName.grid(row=1,column=0) self.firstNameVariable = StringVar() self.firstName = Entry(self, textvariable=self.firstNameVariable, font=("Calibri", 12)) self.firstName.grid(row=1,column=1) self.lblastName = Label(self, text="Last Name:", font=("Calibri", 12)) self.lblastName.grid(row=2,column=0) self.lastNameVariable = StringVar() self.lastName … | |
Re: For me it should be (even You did not send definition of j object): [CODE]jntStringList='' for j in tmpJnts: jntStringList+=j.name()+' ' jntStringList=jntStringList[:-1] ## remove ' ' in the end [/CODE] | |
Re: Like they say: "If nothing else succeeds, read the manual". [QUOTE][B]7.2. Reading and Writing Files[/B] open() returns a file object, and is most commonly used with two arguments: open(filename, mode). >>> f = open('/tmp/workfile', 'w') >>> print f <open file '/tmp/workfile', mode 'w' at 80a0960> The first argument is a … | |
Re: I would myself base the game with dict of places, which would contain dict of things in that place, functions that can be done etc. Of course it would have also list of exists and in case of some special method needed to use the exit, exit function for the … | |
Here is my newest baby, the pretty.py module, born today, which I start to use instead of pprint module. Reason to make this (in addition to that it is possible to do) is that I had this problem, sorry long, LONG example: UPDATE: take out the [CODE]or j[/CODE] that was … | |
Re: Did you check my code snippet for same thing. I keep only set of all full path file names and of course the directories, you could just add all subdirs to path list to keep eye on. [URL="http://www.daniweb.com/code/snippet282009.html"]Watch for change of files in directories[/URL] | |
Re: Give one use case input, result from your program. What user wants? | |
Re: That is one value for all class, maybe you would be better of by only putting [CODE]self.url=url[/CODE] in your __init__? Nice coding with inheritance, good job! | |
| |
Re: I have not also played much with objects in Python so I gave it a go, but using built in sort, as I could not understand the organisation of poster's code. [CODE]class TennisPro: fields=('name','rank','tournamentsPlayed', 'country', 'racquetBrand') def __init__ (self, name, rank, tournamentsPlayed, country, racquetBrand): self.values=[] self.name = name self.values.append(self.name) self.rank … | |
Re: What you want with %a format. You should have %s for strings, %f for floats, %i for integers %x for hexadecimal. I never heard about %a , %b or %c formatting. | |
Re: [QUOTE=snippsat;1218057]Sneekula code will work fine for CSV string. Just make and other version,that do just the same. Maybe better looking,not that it matter so much at all. [/QUOTE] It is recommended to let automatic line continuation to take care of continued line. I have my own style here is how … | |
Re: You forgot the code tags (# button before pasting). [QUOTE=jpl1993;1217251]so i'm almost done with my project. however, i'm still getting some errors when i run. you can find my code below. if you see any problems and know how to fix them, please, please, please let me know! [CODE]class tennis: … | |
Re: another point is the line 172 how it is reached. Did you consider my example of string search. It would be also nice if you could keep the discussion in one thread. | |
Re: Yes, this should work better: [CODE]Dictionary=set(open("e:/assignment/dictionary.txt").read().split())[/CODE] | |
Re: I would do the search myself as for me Python is more powerful in many cases as regular expression language, which is like code language. How ever, as they say: "Somebody likes the daughter, somebody else the mother." Here my 5 minute code with text from above link of re … | |
Re: From your links I only get error from my browser, but this [CODE]from urllib2 import urlopen[/CODE] already looks right for me. Does it not work the way you expect? Check the module's documentation: [url]http://docs.python.org/library/urllib2.html[/url] | |
Re: I do not know about this Beautifull soup and your url did not function for me, but I tried with other url your pickup of data by filtering by partition <a> tags from New York Times. It seemed fast enough for me. [CODE] from urllib2 import URLError,urlopen import re def … | |
Re: inventory is function name, you are trying to overload it by global variable name in that very function! How about making the inventory set, makes more sense to me. [ICODE]global inventory[/ICODE] is unnecessary, as you are not changing things in inventory in your function. Also you can use: [CODE]print "You … |
The End.