Seeing that there is a space in your text on either side of the number, you should add spaces to your pattern so that it is like this:
[code=python]
pattern = re.compile(r': (.*?) \(')
[/code]...
User Profile
Collapse
-
You should read the posting guidelines to learn aboutCode:tags, as they increase the readability of your posts, thereby making it easier for the other forum members to answer your question! Unfortunately, Python's open() call is not intuitive enough to look at a wildcard the same way that the command line does. However by using the os module there are some ways around that. I'm not sure exactly how you want your program to work in terms
Leave a comment:
-
-
Oh wait.. now I see what you were trying to do...
[code=python]
>>> def print_n(n):
... while n > 0:
... print n % 10,
... n = n / 10
...
>>> print_n(492)
2 9 4
>>> [/code]
Modulus 10 will give you the remainder but you want to integer divide by 10 each time to reduce the number another digit.Leave a comment:
-
In python % is the modulo operator... I'm not sure what you are trying here...
Here's how to reverse the digits of an integer using list comprehension:
[code=python]>>> def print_digits(n) :
... new_n = [lett for lett in str(n)]
... new_n.reverse()
... print ''.join(new_n)
...
>>> print_digits(13 6)
631
>>> [/code]Leave a comment:
-
There is a work around that I use in a situation such as yours... at the end of all my code I simply put the following:
[code=python]
raw_input( 'Press enter to quit' )
# This message is completely arbitrary, btw...
[/code]
This way the console will stay open and wait for the user to press enter before quitting.Leave a comment:
-
You could simply store username and password as members of whatever class is represented by self.
In your function initialization of login, have default values for those parameters, then at the beginning of the function, if the values are default, try the self.username and self.password values.
I do not know of any way to actually pass parameters for a bound function without actually calling it, however.Leave a comment:
-
[code=python]
>>> x = [1,2,3]
>>> sum( [ i**2 for i in x ] )
14
>>>
[/code]
Why the type conversion?Leave a comment:
-
FYI, Base 2 = Binary. Base 10 = Decimal. What are you trying to say in that first line there? Are you trying to say that Python handles two-digit precision floating-point numbers? And if so, how?...Leave a comment:
-
Maybe wait for a new version of Python?? :(
This is for sure frustrating for many, and I have a feeling that the guys working on each new version of Python keep this in mind. What version of Python do you use, for curiosity's sake?...Leave a comment:
-
You can use a combo of package_dir and py_modules as below (where the packages I wanted to include in the distributable file were ../Common/[logfile, remoteCmd, and crc32])
[code=python]
setup(
zipfile = None,
# We use os.path.join for portability
package_dir = {'': os.path.join('. .', 'Common')},
py_modules = ['logfile', 'remoteCmd', 'crc32'],
windows = [
{
...Leave a comment:
-
I think this may take dirty tricks... Python isn't the most friendly floating point language and Decimal is nice as long as you're keeping it "in the family", as in not converting back to any other types (except string). So if there is a way for your instrument to accept a string representation of a value you could simply wrap str() around your result... other wise you'll have to do some dirty work.
You could possibly overload...Leave a comment:
-
This is not a Python related question. Please post this question in the proper forum. Also, please use code tags in the future. Read the Posting Guidelines for tips on how to use tags in your posts.Leave a comment:
-
In case you're still wondering the if, else structure in Python is:
[code=python]
if condition 1:
action 1
elif condition 2:
action 2
elif condition 3:
action 3
else:
default action
[/code]Leave a comment:
-
I cannot recommend this enough, but if you're looking for some great learning examples you should head on over to diveintopython. org and pick up a copy of the book for download. When you download the pdf file you will get a ton of example code.
If you're looking for example wxPython code head on over to the wxPython download page and download the wxPython docs, demos and tools package, which will give you an interactive demo that...Leave a comment:
-
Please use code tags in your posts. Refer to the Posting Guidelines about how to properly respond to questions....Leave a comment:
-
I've gotten bitmaps to work before in wxPython, however I've never attempted such an act in PyGame. In order to get a bitmap into a wx-friendly format I used the following:
[code=python]
bmp = wx.Image('Splas h.bmp', wx.BITMAP_TYPE_ BMP, -1).ConvertToBit map()
[/code]
And then in your code you would use
[code=python]
quit.SetBitmap( bmp)
[/code]
Please let us know if that helped at all......Leave a comment:
-
You would have to write your own utility for parsing the file, but it would probably be something like this:
[code=python]
f = open( my_prog.py, 'r' )
for line in f:
data = line.split('=')
if len( data ) == 2:
var_name = data[0]
try:
var_val = int( data[1] )
# Now you can change the value to whatever you want
...Leave a comment:
-
Google the python module xlrd ... it'll take care of data extraction for you.Leave a comment:
-
It should search recursively but for sanity's sake open up a Python shell and type in:
[code=python]
>>> import sys
>>> sys.path
['', 'C:\\WINDOWS\\s ystem32\\python 24.zip', 'C:\\Python24\\ Lib\\site-packages\\wx-2.8-msw-unicode\\wx\\py ', 'C:\\Python24\\ DLLs', 'C:\\Python24\\ lib', 'C:\\Python24\\ lib\\plat-win', 'C:\\Python24\\ lib\\lib-tk', 'C:\\Python24', 'C:\\Python24\\ lib\\site-packages', 'C:\\Python24\\ lib\\site-packages\\pytho nutils',...Leave a comment:
No activity results to display
Show More
Leave a comment: