Suppose you have some this String (one line)
10.254.254.28 - - [06/Aug/2007:00:12:20 -0700] "GET
/keyser/22300/ HTTP/1.0" 302 528 "-"
"Mozilla/5.0 (X11; U; Linux i686
(x86_64); en-US; rv:1.8.1.4)
Gecko/20070515 Firefox/2.0.0.4"
and you want to extract the part between the GET and HTTP (i.e., some url) but only if it contain...
Possible Duplicate:
Replacements for switch statement in python?
I'm making a little console based application in Python and I wanted to use a Switch statement to handle the users choice of a menu selection.
What do you vets suggest I use. Thanks!
...
I'm creating a desktop application that requires authorization from a remote server before performing certain actions locally.
What's the best way to have my desktop application notified when the server approves the request for authorization? Authorization takes 20 seconds average on, 5 seconds minimum, with a 120 second timeout.
I co...
keepProgramRunning = True
while keepProgramRunning:
print "Welcome to the Calculator!"
print "Please choose what you'd like to do:"
print "0: Addition"
print "1: Subtraction"
print "2: Multiplication"
print "3: Division"
#Capture the menu choice.
choice = raw_input()
#Capture the numbers you w...
Newbie python here. How can I break out of the second while loop if a user selects "Q" for "Quit?"
If I hit "m," it goes to the main menu and there I can quit hitting the "Q" key.
while loop == 1:
choice = main_menu()
if choice == "1":
os.system("clear")
while loop == 1:
choice = app_menu()
...
Is it possible to schedule an event in python without multithreading?
I am trying to obtain something like scheduling a function to execute every x seconds.
...
Possible Duplicates:
Python - Parse String to Float or Int
How can I convert a string to an int in Python?
The output I'm getting for my little example app is the following:
Welcome to the Calculator!
Please choose what you'd like to do:
0: Addition
1: Subtraction
2: Multiplication
3: Division
4: Quit Application
0
Enter yo...
The output I'm getting for my little example app is the following:
Welcome to the Calculator!
Please choose what you'd like to do:
0: Addition
1: Subtraction
2: Multiplication
3: Division
4: Quit Application
0
Enter your first number: 1
Enter your second number: 1
Your result is:
11
This is because the addition() method is taking the ...
I have a list of product names in Chinese. I want to translate these into English, I have tried Google AJAX language API, but it seems that translation is not good, it would be great if someone could give me some advice about or point me towards a better choice.
Thank you.
...
Hi,
when I run my programs from within Eclipse IDE the following piece of code works perfectly:
address_name = self.text_ctrl_address.GetValue().encode('utf-8')
self.address_list = [i for i in data if address_name.upper() in i[5].upper().encode('utf-8')]
but when running the same piece of code directly with python, I get an "UnicodeD...
Hi folks,
I've been asked to encrypt various db fields within the db.
Problem is that these fields need be decrypted after being read.
I'm using Django and SQL Server 2005.
Any good ideas?
...
say I have the following code:
def func(x, y = 1, z = 2):
""" A comment about this function """
return x + y + z
another_func = partial(func, z = 4)
What would be the correct or Pythonic way of documenting the another_func function?
...
I'm creating a GUI using Tkinter/ttk in Python 2.7, and I'm having an issue where a Frame will resize itself once a widget is placed inside of it. I am new to Python and haven't used Tkinter before.
example:
ROOT = Tk()
FRAME = ttk.Frame(ROOT, width=300, height=300, relief='groove')
FRAME.grid()
ROOT.mainloop()
will produce a groo...
I have just made a small little app of a Python wxPython script with py2app. Everything worked as advertised, but the app is pretty big in size. Is there any way to optimize py2app to make the app smaller in size?
...
I have a weird list built in the following way:
[[name_d, 5], [name_e, 10], [name_a, 5]]
and I want to sort it first by the number (desc) and then, if the number is the same, by the name (asc). So the result I would like to have is:
[[name_e, 10], [name_a, 5], [name_d, 5]]
I tried to think to a lambda function that I can use in t...
In my code I have a line similar to this:
rval = subprocess.call(["mkdir",directoryName], shell=True)
and I can check rval to see if it is 0 or 1, but if it is 1, I would like to have the text from the command "A subdirectory or file ben already exists." in a file format, so I can compare it to another file if I want to make sure the ...
I'm trying to scrape the information from Google Translate as a learning exercise and I can't figure out how to reach the content of this span tag.
<span title="Hello" onmouseover="this.style.backgroundColor='#ebeff9'"
onmouseout="this.style.backgroundColor='#fff'">
Hallo
</span>
How would I...
I noticed pylint doesn't handle well the case of:
@property
def foo(self):
return self._bar.foo
@foo.setter
def foo(self, foo_val):
self._bar.foo = foo_val
Though it's a perfectly valid case syntax since python2.6
It says I defined foo twice, and doesn't understand the ".setter" syntax (Gives E1101 & E0102).
Is there a workar...
I downloaded beautifulsoup.py for use on a little project I'm making. Do I need to import this .py file in my project?
Do I just copy and paste the code somewhere inside my current python script?
Thank you for the help.
I found this but it doesn't say anything regarding Windows.
http://mail.python.org/pipermail/tutor/2002-April/0139...
Hey,
I am trying to parse a list of data out of a file using python - however I don't want to extract any data that is commented out. An example of the way the data is structured is:
#commented out block
uncommented block
# commented block
I am trying to only retrieve the middle item, so am trying to exclude the items with hashes a...