761 Posted Topics
![]() | Re: Sounds like you'd want to spawn two threads. One to constantly update mytime and another to wait on the user's input. Is that what you mean? I'm pretty sure vegaseat has provided a number of examples of spawning threads with subprocess, try searching the forum for some good examples ![]() |
Re: [QUOTE=zublacko;846010]Ok I have a while loop set but can you guys give me an example of a while loop that takes information, reads the more specific detail and then another specific detail? In my code I cant figure out how to make the loop search another line or sentence. All … | |
Re: After you perform [icode]x = s.find("<img")[/icode] you will receive an index. Feed this index into the find function when looking for your closing parenthesis and it will give you the ending index. You can then use the two indexes to slice out the image source URL here's an example (off … | |
Re: [QUOTE=harrykokil;838851]how can i create 50 apples at different positions on screen without having to each time call the constructor 50 times? [/QUOTE] Just put the call to the Apple constructor within your for loop and randomize the values a bit... or use a linear approach to the values... or whatever … | |
Re: I think the function you may be looking for in Python is [icode]eval[/icode]. Or perhaps [icode]exec[/icode], or its variant [icode]execfile[/icode], which eliminate reading the files all together. [URL="http://docs.python.org/library/functions.html#eval"]Refer here[/URL] to information on these built-in functions. As far as how to open files within a for loop it could be something … | |
Re: [QUOTE=mg0959;842048]Running it as a service works great!!! thanks for the help[/QUOTE] What did you do to get it running as a service? | |
Re: I notice that your condition 3 is missing a continue statement... To answer your question however, you should check to see if intWork is greater than 40 and if it is, calculate the overtime based on the number of hours over 40 that the employee worked. | |
![]() | Re: [QUOTE=Hatz2619;841136] [CODE=python] try: salariesWage=open("PAY.txt", "w") salariesList.writelines(salaries) salariesWage.close() except(IOError): print "Error writing to file list" ... try: employeeWage=open("PAY.txt", "r") employeeList.readlines(salaries) employeeWage.close() except(IOError): print "Error writing to file list"[/CODE] [/QUOTE] Upon initial inspection I see that you're opening PAY.txt as salariesWage and then employeeWage but then trying to read/write as salariesList and … ![]() |
Re: [QUOTE=dmpop;841319]the script still doesn't work[/QUOTE] What doesn't work? If you are getting error messages please paste the traceback here. | |
Re: This code doesn't really do anything for me... can you explain the concept a little bit? When none of the menu choices do anything except for the 'new maze' bit. Printing shows the maze but neither solve nor "Remove v's" does anything whatsoever. I'm not getting errors though... | |
Re: You're looking to remotely shutdown a linux server? Or to quit a python program? [icode]sys.exit(rtn_code)[/icode] can exit a python program... but I'm not sure if that's what you're looking for. | |
Re: I don't understand... is there a question hidden within these cryptically edited posts? | |
Re: [URL="http://www.crummy.com/software/BeautifulSoup/"]Beautiful Soup[/URL]. If you search this forum there's plenty of examples using it, as well as the numerous other parsers out there. | |
Re: [QUOTE=tillaart36;790853]It should iterate as (x, y) [/QUOTE] You just have your x and y mixed up: [code=python] >>> def printGrid(w,h): ... for y in xrange(h): ... for x in xrange(w): ... print '%d,%d' % (x,y), ... print ... >>> printGrid(w=7,h=6) 0,0 1,0 2,0 3,0 4,0 5,0 6,0 0,1 1,1 2,1 … | |
Re: You could use the python debugger to put a break statement I guess? I'm not terribly versed in using it, but from my limited exposure I know that you can put break statements and step through loops, etc. just like most other debuggers. In order to use it you have … | |
Re: [QUOTE=LateNiteTippin;835806]I'm very new to python, so this is very basic. I'm using the same basis i used on an add row program, which is probably why it comes up adding a row. When i read it back to myself, it seems to make sense. Thanks in advance for any help. … | |
Re: [QUOTE=Gribouillis;836181]google is your friend [url]http://commons.wikimedia.org/wiki/File:Dragon_curve.png[/url][/QUOTE] Wow. I love that db replaced the text within that hyperlink with a smiley. I'm sorry this post isn't on topic but I just wanted to get that out there. Hey, and the link still works! EDIT: kette = chain laenge = length zeichne = … | |
Re: Please provide the current state of your code and the problems that you are currently having. Please be specific and show us the exact portion of code that is broken and any error messages that you receive. Do not forget to [URL="http://www.daniweb.com/forums/announcement114-3.html"]wrap your code[/URL] in code tags to preserve formatting. … | |
Re: [QUOTE=pythonnewbie1;835916][code=python] #creating a Class # class wpoMath(object): """This is a Math object""" #main program wpoMath1=wpoMath() wpoMath1.talk() def _init_(self,wpoMath): print "I am wpoMath object" self.name = wpoMath print wpoMath1.wpoMath def _str_(self): print "Hi, I'm, wpoMath, "\n" self._wpoMath=wpoMath def get_wpoMath(self): return self._wpoMath def _init_(self, plus): self.plus = plus def _str_(self): doubled = … | |
Re: This might be the easiest thing to do: [code=python] fh = open('myfile.txt') for each_line in fh: print each_line.strip().replace(':', '|') fh.close() [/code] That'll iterate line by line through the file and print out each line only replacing all occurences of ':' with '|'... You could alternately use methods read(), readline(), or … | |
Re: [url=http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files]Here's some documentation[/url] on the file object and associated methods. | |
Re: You've got numerous indentation errors in your code as vegas seat mentioned... first off, fix your lines 2-5 above, as they need to be at the same indentation level as your first if statement... Then work from there, as you've got a LOT of work to do to get this … | |
Re: Also please post code using code tags, as it preserves the formatting and highlights reserved words (such as file). This will increase the chance that other forum members will read your post and be more willing to help. Use code tags like this: [noparse][code=python] #You code goes here [/code][/noparse] | |
Re: [QUOTE=Darkangelchick;823323]does anyone know if it's possible to make this using Tkinter?[/QUOTE] Yes, it is. Coming up with a design for the game board (colors, sizes, etc.) might be the hardest part. We can help you once you get started if you get stuck on anything, just don't forget to post … | |
Re: What do you need help with? Do you know how to define a class yet? Here's some [url=http://docs.python.org/tutorial/classes.html]documentation[/url]. | |
Re: What exactly do you need explained? Also, in stead of [python] you should be using code tags. To get language-specific syntax highlighting use it like this: [noparse][code=python] # Code in here [/code][/noparse] | |
Re: Karen, Please use code tags when posting code, or else it will become unreadable as it has above. To use the code tags, wrap your code like this: [noparse][code=python] # Code inside here [/code][/noparse] This will turn on syntax highlighting and preserve your indentation. Also, forum members are [b]much[/b] more … | |
Re: You can use a regular expression to grab the number of differences... please ask if there's anything you don't understand. [code=python] >>> import re >>> # my_file_handler = open( 'myfile.txt' ) >>> # my_file_lines = my_file_handler.readlines() >>> # Here's the contents of my_file_lines after a readlines() >>> # my_file_lines = … | |
Re: [QUOTE=alicem;826881]Thank you, however I'm using Python 2.6.1... is there a different way to do it using that?[/QUOTE] Maybe try this.. pretty much same principal as 3.0 : [code=python]fh = open('myfile.txt', 'rb') while True: try: fh.read(1) except: pass [/code] | |
Re: I don't believe that there is a way to ensure Python is un-reverse engineer-able... Meaning that even Python byte code programs can be translated back to source code if someone were dedicated enough to do it. That being said, I used to be a C++ programmer until I discovered Python. … | |
Re: Please use code tags when posting any type of code [noparse][code=syntax] # Code goes here [/code][/noparse] syntax can be replaced with any code that is supported by DaniWeb like: python, php, etc. | |
![]() | Re: Did you download and install mpgedit? The link is provided above... ![]() |
Re: I would highly suggest reinstalling and making sure you install under admin for everything. | |
Re: Remove an item from a list: [code=python]>>> B = [12,24,36,48,60,72] >>> B.remove(24) >>> B.remove(48) >>> B.remove(72) >>> B [12, 36, 60] >>> [/code] | |
Re: I find that best practice is to always use [icode]strip()[/icode] on lines that I read in from files. This gets rid of all leading and trailing white-space (tabs, spaces, newlines, etc.) Also, here's a rewrite of your code... I removed the tabs and replaced them with spaces and also stripped … | |
Re: [QUOTE=patelmitul;822211] [CODE=python] import os, glob path = 'd:\del' for my_file in glob.glob( os.path.join(path, '*.jpg') ): (dirName, fileName) = os.path.split(my_file) (fileBaseName, fileExtension) = os.path.splitext(fileName) print fileBaseName[/CODE] [/QUOTE] Are you getting errors? You don't need to import os.path, as you can simply use os.path after importing os... Also, you aren't using the … | |
Re: [icode]f.seek(0)[/icode] will always return to the beginning of a file as well. If you print out the value of [icode]beginning[/icode] in the code snippet above, you'll likely find that it is an integer == 0. | |
Re: Not sure exactly what you're asking... but you could make a list of tuples list: [code=python] my_list = [ (0,0), (0,1), (1,1), (1,2) ] [/code] ? Is that what you're asking? | |
Re: [QUOTE=pythononmac;818565]I have put # -*- coding: utf-8 -*- on the top of the script [/QUOTE] If you remove that line from the top of your script does it change the result? Also, have you tried utf-16 ? | |
Re: Here's a class example... [code=python]>>> class car(object): ... def __init__(self, make='Any', model='Something', year='Unknown'): ... self.make = make ... self.model = model ... self.year = year ... def __repr__(self): ... return 'Hello, I am a %s %s %s' % (self.year, self.make, self.model) ... >>> my_car = car('Ford', 'Focus', '2008') >>> your_car … | |
Re: Until py2exe works with Python 3 you're out of luck... if you can get your users to install Python 3 then all they have to do is double click on the script to run it... | |
Re: First of all, you should use code tags like such: [noparse][code=python] # Code goes in here [/code][/noparse] Which would've given you the following: [code=python]if param[0:4]<>'ini=': print ' %s ini='%sys.argv[0] sys.exit(1) inifile=param[4:][/code] Now, to answer your question: First we check that the first 4 characters of param are "not equal" to … | |
Re: [QUOTE=Norbert X;817803]I need help with my homework :( but no one's replying. [note: this comment was just to move this thread back to the top of the list][/QUOTE] This isn't a place to come and have your homework done for you. Forum-goers here typically don't just give out solutions to … | |
Re: Here's how to open a file and parse the contents as per your example: [code=python] def main(): """ test_data.txt contents (minus leading tabs): 2.825 1.00697992588 2.875 0.952989176901 2.925 0.91428970229 2.975 0.890110513425 3.025 0.879731596138 3.075 0.959217137445 3.125 1.07391392796 3.175 1.04874407027 3.225 0.857693793906 """ # We can keep track of our data … | |
Re: What do you mean by "play" ? Are you wanting to have an image pop up in a window or are you talking about playing a video file? | |
Re: [QUOTE=g_e_young;815957]file_list ends up with the final value from data, rather than a string of all values in the file [/QUOTE] On every iteration you're simply over-writing the value of file_list. The proper way to use a list is: [code=python] my_list = [] for line in my_file: my_list.append( line ) [/code] … | |
Re: Why reinvent the wheel? Python has a text wrapping module [url=http://docs.python.org/library/textwrap.html]built right in[/url] | |
Re: [QUOTE=wccarithers;815738]I am using psycopg2 to read from one database table and insert these into another table. I get a format error when the value I am trying to insert has a space in it. The condensed code looks like: cursor.execute("""INSERT INTO table (column1, column2) VALUES ('start finish','now later')""") I'm a … | |
Re: My thoughts: Traverse the grid from top-to-bottom, and left-to-right (ie, just like reading a book). On each character, make a list of *this letter concatenated with every surrounding letter (for this example we'll start at the left or due west position and progress counter-clockwise, ie: [code=concept] grid = """ ashfghj … | |
Re: I assume that re-ordering is due to the way that dictionaries are stored in memory... in order to provide faster searching and indexing dictionaries are stored in a special way... much unlike lists and tuples, which retain their order.... Example: [code=python] >>> d = {'cat':'purr', 'dog':'woof', 'aardvark':'?', 'chocolate rain':'feel the … |
The End.