761 Posted Topics
Re: Could you give us the offending code and the Traceback? Your explanation is devoid of any information that could allow us to help you. Help US help you! | |
Re: You are right as to why this is happening; a variable and a function sharing the same name. From within the class scope, self.number is the variable and self.number() is the function. When you initialize the class, it goes through and recognizes each function then calls __init__ (at least that's … | |
Re: After you open the file for reading you can iterate over each line like so: [code=python] fh = open('myfile.txt', 'r') lines = fh.readlines() fh.close() for each_line in lines: ## split each line now like woooee pointed out above and do your processing... [/code] | |
Re: makeSentence is a function of the class App. It should be called as such [icode]App.makeSentence[/icode] | |
Re: Here's one making use of list comprehension: [code=python] >>> def FirstLetters( s ): ... return ''.join( [ lett[0] for lett in s.split() ] ) ... >>> FirstLetters( 'My mother used to bake apple pies in the foo bar' ) 'Mmutbapitfb' >>> [/code] | |
Re: You can identify substrings using the () characters within your pattern; for example: [code=python] >>> import re, os, sys >>> tests = [ 'NM4_ACT', 'NM4_SAND', 'NM3_BOO', 'NM5_FOOBAR', 'NM4_DUMP', 'NM4_SUNSET', 'NM4_SOUTH_VALLEY' ] >>> for each in tests: ... ret = re.search('^NM4_(.*)$', each) ... if ret: ... ret.groups() ... ('ACT',) ('SAND',) ('DUMP',) … | |
Re: Here's a few things to get you on your way: [code=python] >>> inp = 'clear|foobar' >>> inp.find('clear|') 0 >>> inp.rfind('|') 5 >>> inp[5+1 : ] # This is slicing 'foobar' >>> inp.split('|') ['clear', 'foobar'] >>> inp.split('|')[1] 'foobar' >>> [/code] | |
Re: The usage depends on what interface you're using to make your client/server (I've only ever used paramiko); however you could probably make use of a global timeout setting. This way after a set amount of time the recv() operation will throw a timeout exception, which you can catch and handle … | |
Re: What? Are you asking about two variables of the same name ? Or are you asking about a private variable that can only change through a public modifier? | |
Re: Have you looked into pyExcelerator at all? I'd say it's worth a shot. [url=http://sourceforge.net/projects/pyexcelerator]link[/url] | |
Re: Not exactly sure what it is you're looking for. But many built-in objects can have the str() function applied to them with little problem. If it's a custom class or similar you may need to look into the Pickling module. I don't know if you plan to use the string … | |
Re: Since there is no A2 in your code; and judging by the content of the error message; I would assume that you have imported the maya.cmds module incorrectly. I would look into the documentation for an example of how to properly use said module. | |
Re: Here's how you could iterate through a file: [code=python] fh = open( 'myFile.txt', 'r' ) inp = fh.readlines() fh.close() for each_line in inp: # Do something here [/code] All you'll need to do is make a counter and increment it when you find what you're looking for. | |
Re: If your regex doesn't match anything it returns a None, which gets stored to m. You should have a check before accessing m.groups by saying [icode]if m:[/icode] | |
Re: You can interact with Python and execute code as you see fit. My favorite thing about Python is being able to simply type in examples to the Interpreter and see how my programs will react to different test cases. | |
Re: Hmm, it's hard to say exactly what's wrong without having an example of the contents of table.csv; however upon initial inspection I see a glaring problem. Since you're not incrementing counter by 1 (rather a variable length), I would imagine you're missing the opportunity to enter the [icode]while counter == … | |
Re: I don't know about getopt but all of those things are stored in the list stored under sys.argv [code=python] >>> import sys >>> sys.argv[0] >>> len(sys.argv)[/code] Try those lines and then you should be able to handle the command line arguments yourself. | |
Re: There are a number of problems here. First of all, that text file contains five letter words that are all appended together without any whitespace whatsoever. Secondly, do not use file as one of your variable names. As you can see above, file is highlighted in purple meaning that it … | |
Re: [code=python] import sys, os if len(sys.argv) != 2: print 'Usage: python copy.py <file_to_copy>' sys.exit(0) if sys.platform[:3] == 'win': os.system('copy %s %s' % (sys.argv[1], 'copy' + sys.argv[1])) elif sys.platform[:5] == 'linux': os.system('cp %s %s' % (sys.argv[1], 'copy' + sys.argv[1]))[/code] | |
Re: In my experience with regex you can combine two different regexes with an '|' (or operator). So within the quotes just place a '|' between each regex (without single quotes)' Like so: [code=python] tennis_players = re.compile("<div class=\"entrylisttext\">([\d+]*)</div>|playernumber=[A-Z][0-9]+\" id=\"blacklink\">([a-zA-Z]+, [a-zA-Z]+)|pointsbreakdown.asp\?player=[A-Z][0-9]+&ss=y\" id=\"blacklink\">([0-9]+)|playeractivity.asp\?player=[A-Z][0-9]+\" id=\"blacklink\">([0-9]+)", re.I | re.S | re.M)[/code] | |
Re: This doesn't belong in this forum... however I imagine when you say you "started the CD up" you mean that you're still in Windows and you just popped it into your disc drive. You need to understand that when it comes to an operating system, it's not just another program … | |
Re: When using psycopg2 your operations are only transactions. In order to get your transaction to commit to the database you'll need to issue a [icode]conn.commit()[/icode] command. | |
Re: You can use wxPython to display chm files in a native help window. | |
Re: wxPython, like most other GUI modules is event driven. This means that until something triggers an event, processing is more or less waiting for something to happen. I'm not sure what you mean by appending text afterwards? Do you mean literally after the mainloop() statement? Because the program stays in … | |
Re: A very crude method would be to capture your output, and then execute the same command via os.system or a similar call. Alternately you could make use of smtplib to send the email to a mail server's listener, and send it that way. Example of [url=http://docs.python.org/lib/SMTP-example.html]using smtplib[/url]. Keep in mind … | |
Re: [] designates a group of characters to match.. you had [d+] in there, meaning that you wanted to match any of the digits 0-9 as well as the plus symbol. An equivalent statement would be [0-9+], or typing the entire set of digits out would be [0123456789+]. By placing an … | |
Re: Google Byte of Python and Dive into Python. Both are great launching pads for getting into some serious Python programming. The latter is more for people that are familiar with programming languages in general, while the first is more for somebody that is using Python as their first programming language … | |
Re: You can simply store the data of the previous line in a variable, so that on the following iteration you can calculate with the previous line and the current one. | |
Re: What do you mean freeze them but still scroll? Would you simply want to not allow the user to expand any items in the tree ? And not allow any checklistbox items to be 'checked'? This would be as simple as binding an event to those actions and if your … | |
Re: You're on the right track! However I typically like to use slicing when I know precisely where on a line the information that I'm looking for is going to be. Here's what you suggested in a friendly python format: [code=python] inp = open('SAdatabsse.txt', 'r') outp = open('SAdatabse2.txt', 'w') for eachline … | |
Re: [code=python] def chckguess(guesses) #guesses = 0[/code] By declaring [icode]guesses = 0[/icode] at the beginning of your function you are resetting its value. Also guesses being defined within the function only gives that variable scope within that function. You should either have that variable be global, and then within the function … | |
Re: You will need to download and install pyExcelerator as it is not distributed with the standard Python. Link: [url=http://pypi.python.org/pypi/pyExcelerator/0.5.3a]Py Package[/url] You cannot create a csv file with multiple sheets (tabs), as the format does not allow it. | |
Re: You would need to keep track of the boundary of 'square', which would be the leading edge of movement (this gets really complicated if square is rotating while falling), and then do a comparison to make sure that the leading edge isn't at the line... if it is past the … | |
Re: This is not a Python issue, it is an Access issue. If you can perform the query in Access it will work through Python you just need to be careful as to how you format your query. If you paste the query that you would use from within Access, we … | |
| |
Re: Could your main thread keep a dynamic dictionary or list of the process ids ? Then you could perform some basic system commands to see which theads are still running and kill them if necessary? | |
Re: You bind an event to intercept the maximize event and call an event.veto() | |
Re: [code=python] >>> md = {} >>> md['a'] = [1,2,3,4] >>> md['h'] = (1,2) >>> md['t'] = {'first':[9,8,7], 'sec':(1,2,3,4), 'h':'foobar'} >>> md {'a': [1, 2, 3, 4], 'h': (1, 2), 't': {'h': 'foobar', 'sec': (1, 2, 3, 4), 'first': [9, 8, 7]}} >>> [/code] Is that what you mean by multiple … | |
Re: [QUOTE=MikeyFTW;651479] i want it to be able to load the program up and then be able to choose from addition as well as substraction like a button for each on start up or something.[/QUOTE] What if you had a radio button choice. So that addition and subtraction could be chosen … | |
Re: Yes there are not only GUI toolkits for PYthon where you could make a very nice looking UI for the user, but python scripts can also simply be double-clicked to have them execute. | |
Re: I've used a module called paramiko to open a tunnel into another machine and execute commands remotely. It worked very nicely. | |
Re: Before your for loop you should initialize a5 and a6 as ''. Then within your loop instead of a5 = or a6 = you should use += to concatenate. | |
Re: if you can type exactly that command into your command window, then os.system() with *exactly* that command will work. What doesn't work about it? Are you getting an error? | |
Re: What have you tried so far? Give us what you've already done and we can help you along. However we cannot simply do this for you because then you wouldn't learn anything. | |
Re: First, you need to use code tags on your code to make it readable and not lose your inentation. Your line [icode]for (first, second) in pairs:[/icode] is along with your error suggesting that pairs is being passed in as an integer. When you provide an example code it would help … | |
Re: When you are calling wx.DirPickerCtrl( ) simply place the size that you want in the initialization like so: [icode]wx.DirPickerCtrl( self, -1, '', 'My Dir Picker', size = (a, b) )[/icode] where a and b are the desired dimensions. You could also set the size after the fact with [icode] my_picker.SetSize( … | |
Re: > `yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))` Yes, Python is not a scientific calculator so it does not know that `(x-5)(x-4)` has an assumed multiplication between parenthesis. You will need to be more specific so change your line to yIntercept = y1 - ( ( ( y2 … | |
Re: There are a few possibilities I can think of, but probably the most straight forward: [code=python] >>> li = [ 1, 2.3, 4e-5, 'hey!' ] >>> for item in li: ... test = str(item) ... if test == item: ... print item, 'String!' ... else: ... print item, 'Not String!' … | |
Re: Here are a few modifications I made: [code=python] name = raw_input("\t\t\tPlease Enter Your Name: ") print print "\t\t\t\tHello", name print "\t\t\tWelcome to my Mathematics Game" # Selecting the operation of Addition and Substraction followed by the difficulty print operation = str(raw_input("\t\t\tAddition (A) or Substraction (S)")) if operation == "A" or … | |
Re: You could simply change the password in the script and then run main() again. |
The End.