3,386 Posted Topics

Member Avatar for persianprez

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: …

Member Avatar for ultimatebuster
0
157
Member Avatar for G-nom

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 …

Member Avatar for woooee
0
114
Member Avatar for Steven.T

to continue from vegaseat's hint: ...and you must deal with punctuation being put together with previous/following word.

Member Avatar for TrustyTony
0
1K
Member Avatar for mysticstylez

Consider which of next words must be replaced if 'of' is in word list: [CODE]'''off shore switch off often "of course" of.'''[/CODE]

Member Avatar for griswolf
0
3K
Member Avatar for cableguy31

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.

Member Avatar for TrustyTony
0
106
Member Avatar for haydensewell

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 …

Member Avatar for vegaseat
0
2K
Member Avatar for stabzagg

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, …

Member Avatar for morgadao
0
5K
Member Avatar for niehaoma

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 …

Member Avatar for TrustyTony
0
123
Member Avatar for TrustyTony

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 …

Member Avatar for TrustyTony
0
1K
Member Avatar for Etinnet

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.

Member Avatar for TrustyTony
0
280
Member Avatar for dbphydb

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

Member Avatar for dbphydb
0
763
Member Avatar for dbphydb

[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 …

Member Avatar for dbphydb
0
175
Member Avatar for CobRalf
Member Avatar for CobRalf
0
767
Member Avatar for albruno

Simple googling braught me this among others: [url]http://developer-resource.blogspot.com/2008/06/python-and-cuda.html[/url]

Member Avatar for 0x69
0
139
Member Avatar for alabandit

Incorrect: [CODE]>> string = 'this is a test string' >>> string[:-10] 'this is a t' >>> ## right way >>> string[-10:] 'est string' >>> [/CODE]

Member Avatar for alabandit
0
260
Member Avatar for MJFiggs

Set pythonpath environment variable to point to location of the cTurtle.

Member Avatar for ultimatebuster
0
166
Member Avatar for TrustyTony

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.

Member Avatar for TrustyTony
0
236
Member Avatar for TitusPE

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.

Member Avatar for TrustyTony
0
8K
Member Avatar for Kacoo

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?

Member Avatar for jcao219
0
180
Member Avatar for Aeronobe

You must add .split(eol) or do .partition(eol) by some end of line tag or '\n' according to your need.

Member Avatar for Aeronobe
0
145
Member Avatar for Kruptein
Member Avatar for xxxchopsakexxx

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.

Member Avatar for HiHe
0
343
Member Avatar for TrustyTony

Here is way to put easily editable layout for input fields with standard look and collect the text variables to list for use.

0
2K
Member Avatar for nsutton

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 …

Member Avatar for nsutton
1
228
Member Avatar for vandalised

(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 -> …

Member Avatar for griswolf
1
2K
Member Avatar for aint

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 …

Member Avatar for TrustyTony
1
414
Member Avatar for afireinside
Member Avatar for Aeronobe

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 …

Member Avatar for vegaseat
1
169
Member Avatar for TitusPE

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 …

Member Avatar for TrustyTony
0
205
Member Avatar for albertkao

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('.'): …

Member Avatar for jice
0
3K
Member Avatar for macca21

Neat coding vegaseat: [CODE] first, last, score1, score2, score3 = line.split(',')[/CODE]

Member Avatar for TrustyTony
0
195
Member Avatar for Mezzck

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 …

Member Avatar for Mezzck
0
441
Member Avatar for pixeldroid

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]

Member Avatar for TrustyTony
0
246
Member Avatar for ultimatebuster

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 …

Member Avatar for HiHe
0
132
Member Avatar for Lapixx

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 …

Member Avatar for ultimatebuster
0
168
Member Avatar for TrustyTony

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 …

Member Avatar for TrustyTony
0
2K
Member Avatar for alabandit

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]

Member Avatar for alabandit
0
124
Member Avatar for nsutton
Member Avatar for nsutton
0
113
Member Avatar for Aeronobe

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!

Member Avatar for Aeronobe
0
96
Member Avatar for Qwazil
Member Avatar for jpl1993

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 …

Member Avatar for TrustyTony
0
140
Member Avatar for Hawkeye Python

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.

Member Avatar for Hawkeye Python
0
235
Member Avatar for azrael_

[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 …

Member Avatar for TrustyTony
0
216
Member Avatar for jpl1993

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: …

Member Avatar for woooee
0
147
Member Avatar for dreadyteddy

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.

Member Avatar for dreadyteddy
0
232
Member Avatar for Steven.T

Yes, this should work better: [CODE]Dictionary=set(open("e:/assignment/dictionary.txt").read().split())[/CODE]

Member Avatar for TrustyTony
0
185
Member Avatar for jl487

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 …

Member Avatar for TrustyTony
0
11K
Member Avatar for dbphydb

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]

Member Avatar for TrustyTony
0
984
Member Avatar for gunbuster363

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 …

Member Avatar for amrutraj
0
6K
Member Avatar for Lapixx

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 …

Member Avatar for snippsat
0
8K

The End.