Re: [Tutor] subprocess output

2010-07-28 Thread Sander Sweers
- Original message - > I'm using Python 2.6.5 and I've got a challenge with the subprocess > module. I'd like the output to be stored in a variable, and not sent to > the stdout. The relevant lines as they are now: Go to google, enter "pymotw subprocess" and hit I am feeling lucky ;-) gre

Re: [Tutor] subprocess output

2010-07-28 Thread Evert Rol
> #!/usr/bin/env python > import subprocess > import sys > > dom = sys.argv[1] > switch = sys.argv [2] > answer = subprocess.call("whois " + dom, shell=True) > > Execute the above (whatever.py -example.com -a1) prints the entire WHOIS > output, but I just want it saved to the variable 'answer', n

Re: [Tutor] Running .py files in shell

2010-07-28 Thread Kevin Rapley
I am running Mac OSX v10.6.4 Snow Leopard I am running Python 2.6.1 In general get the MacPython distributions of Python etc, they usually install easier (ie from the GUI) than the "Unix" based versions. Okay, thanks. I will look into that. 1. How do I execute .py files in the command line sh

Re: [Tutor] Running .py files in shell

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 2:39 AM, Kevin Rapley wrote: > >>> I am running Mac OSX v10.6.4 Snow Leopard >>> I am running Python 2.6.1 >> >> In general get the MacPython distributions of Python etc, they usually >> install easier (ie from the GUI) than the "Unix" based versions. > > Okay, thanks. I wi

[Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
From a practice exercise in Building Skills In Python page 64 I'm working on How Much Does The Atmosphere Weigh? Part 1: To check it states that the answer should be app. 10**18kg However, and I've checked to make sure that the math I've layed out matches up with the texts, I get 5.07360705863e+20

Re: [Tutor] Calculating and returning possible combinations of elements from a given set

2010-07-28 Thread ZUXOXUS
2010/7/28 Dave Angel > > > ZUXOXUS wrote: > >> Oh, I think i got it: >> >> >> >>> for prod in itertools.product('ABC', 'ABC'): > > print(prod) >> >> ('A', 'A') >> ('A', 'B') >> ('A', 'C') >> ('B', 'A') >> ('B', 'B') >> ('B', 'C') >> ('C', 'A') >> ('C', 'B') >> ('C', 'C') >> >> Thank

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Evert Rol
Sorry, forgot to reply-to-all: I don't know the book nor the exercise, but see my comments interspersed in the code, and a few general remarks at the bottom > From a practice exercise in Building Skills In Python page 64 I'm > working on How Much Does The Atmosphere Weigh? Part 1: > To check it

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Hugo Arts
On Wed, Jul 28, 2010 at 11:41 AM, David Hutto wrote: > From a practice exercise in Building Skills In Python page 64 I'm > working on How Much Does The Atmosphere Weigh? Part 1: > To check it states that the answer should be app. 10**18kg However, > and I've checked to make sure that the math I've

[Tutor] problem with simple script

2010-07-28 Thread Richard D. Moores
I have a practical need for a script that will give me a random int in the closed interval [n, m]. Please see . This works fine when I enter both n and m as, for example, "23, 56", or even "56, 23". But often the closed interval is [1, m], so I'd like to not

Re: [Tutor] problem with simple script

2010-07-28 Thread Luke Paireepinart
Just do a split of the input from the user on space or comma. If Len() of the split data is 1, do your [1, ...] interval, otherwise do the other interval. Sent from my iPhone On Jul 28, 2010, at 6:51 AM, "Richard D. Moores" wrote: > I have a practical need for a script that will give me a rand

Re: [Tutor] problem with simple script

2010-07-28 Thread Nick Raptis
On 07/28/2010 02:51 PM, Richard D. Moores wrote: I have a practical need for a script that will give me a random int in the closed interval [n, m]. Please see . This works fine when I enter both n and m as, for example, "23, 56", or even "56, 23". But of

[Tutor] String replace question

2010-07-28 Thread Rod
Hello, I need to replace a period (.) in a domain name with a slash period (\.). I'm attempting to use the string replace method to do this. Example: uri = domain.com uri.replace('.', '\.') This returns 'domain\\.com' Is there a way to do this so there is not a double slash before the period

Re: [Tutor] String replace question

2010-07-28 Thread Rod
> Try print uri.replace('.', '\.') > and you'll find the replacement works fine. > > Or write the output to file, and look at the file. > > Python shows a representation on its prompt, and thus needs to escape the > backslash (by prepending another backslash). Otherwise you might think '\.'

Re: [Tutor] String replace question

2010-07-28 Thread Nick Raptis
On 07/28/2010 03:41 PM, Rod wrote: Hello, I need to replace a period (.) in a domain name with a slash period (\.). I'm attempting to use the string replace method to do this. Example: uri = domain.com uri.replace('.', '\.') This returns 'domain\\.com' Of course it does! Try to print

Re: [Tutor] Calculating and returning possible combinations of elements from a given set

2010-07-28 Thread Dave Angel
ZUXOXUS wrote: 2010/7/28 Dave Angel Your latest version gets the product of two. But if you want an arbitrary number, instead of repeating the iterable ('ABC' in your case), you can use a repeat count. That's presumably what you were trying to do in your earlier incantation. But you forgot

Re: [Tutor] problem with simple script

2010-07-28 Thread Steven D'Aprano
On Wed, 28 Jul 2010 09:51:40 pm Richard D. Moores wrote: > I have a practical need for a script that will give me a random int > in the closed interval [n, m]. Please see > . What is the purpose of this function? def get_random_int(n, m): return randint(

[Tutor] Plugin system - how to manage plugin files?

2010-07-28 Thread Mac Ryan
Hi everybody, This is more of a python software design question rather than a question on the Python syntax alone. I hope it is fine to ask here. I am working on a small project, that I will release under a GPL license, whose main design guiding principle is extensibility. Thus I

Re: [Tutor] problem with simple script

2010-07-28 Thread Richard D. Moores
On Wed, Jul 28, 2010 at 04:51, Richard D. Moores wrote: > I have a practical need for a script that will give me a random int in the > closed interval [n, m]. Please see . > > This works fine when I enter both n and m as, for example, "23, 56", or even > "56,

[Tutor] Problem with input() and unicode string

2010-07-28 Thread Alex
Hello, I have a problem with this code: # -*- coding: latin-1 -*- year = u'año, ò, ó, ç' print year year = input(u'Introduce el año:') print year raw_input() The first print statement works as expected, both in IDLE and when double-clicking the file for a console view. The second one works in ID

Re: [Tutor] Calculating and returning possible combinations of elements from a given set

2010-07-28 Thread ZUXOXUS
> > 2010/7/28 Dave Angel > > > Your latest version gets the product of two. But if you want an arbitrary >> number, instead of repeating the iterable ('ABC' in your case), you can >> use >> a repeat count. That's presumably what you were trying to do in your >> earlier incantation. But you for

[Tutor] Newbie question - syntax - BeautifulSoup

2010-07-28 Thread Tommy Kaas
I have just begun a struggle learning Python. I have read most of "Beginning Python - from Novice to Professional" - and some of it I even understood J This is my first question to the list. And I'm sure not the last. I'm especially interested in learning web scraping techniques and here: http

Re: [Tutor] Problem with input() and unicode string

2010-07-28 Thread Timo
On 28-07-10 18:05, Alex wrote: Hello, I have a problem with this code: # -*- coding: latin-1 -*- year = u'año, ò, ó, ç' print year year = input(u'Introduce el año:') print year raw_input() The first print statement works as expected, both in IDLE and when double-clicking the file for a console v

Re: [Tutor] Problem with input() and unicode string

2010-07-28 Thread Huy Ton That
You can do: input(unicode('Introduce el año:', 'latin-1').encode('latin-1')) Maybe someone could explain it better than I can. HTH, Huy On Wed, Jul 28, 2010 at 12:05 PM, Alex wrote: > Hello, I have a problem with this code: > > # -*- coding: latin-1 -*- > year = u'año, ò, ó, ç' > print year

Re: [Tutor] Running .py files in shell

2010-07-28 Thread Alan Gauld
"Kevin Rapley" wrote The simplest way is to put a "shebang" line at the top of your script and then make them executable: $ cat> myscript.py What is the significance of this and how do I use it? >>> cat > tryme1.py Notice the difference in the prompt. A dollar sign is the generic way o

Re: [Tutor] Calculating and returning possible combinations ofelements from a given set

2010-07-28 Thread Alan Gauld
"ZUXOXUS" wrote My doubt now is whether I can change the way python show the combinations. Python will display the compbinations however you tell it to. The function generates the combinations the display is up to you. In this case you are simply printing the results as they come. But you c

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Alan Gauld
"David Hutto" wrote To check it states that the answer should be app. 10**18kg However, and I've checked to make sure that the math I've layed out matches up with the texts, I get 5.07360705863e+20 A couple of comments but my Physics is a bit rusty!! import math def atmosphereWeight():

Re: [Tutor] Calculating and returning possible combinations ofelements from a given set

2010-07-28 Thread ZUXOXUS
2010/7/28 Alan Gauld > > "ZUXOXUS" wrote > > > > My doubt now is whether I can change the way python show the combinations. >> > > Python will display the compbinations however you tell it to. > The function generates the combinations the display is up to you. > In this case you are simply prin

Re: [Tutor] Problem with input() and unicode string

2010-07-28 Thread Alan Gauld
"Alex" wrote The first print statement works as expected, both in IDLE and when double-clicking the file for a console view. The second one works in IDLE, but just flashes by when double-clicking the file, due to an error report I can't see. So run it from a Console prompt and you will the

Re: [Tutor] Newbie question - syntax - BeautifulSoup

2010-07-28 Thread Alan Gauld
"Tommy Kaas" wrote for row in soup('table', {'class' : 'spad'})[0].tbody('tr'): The example works fine, and I can change it a bit and it still works. But I simply don't understand how I am supposed to the fourth line - after "for row in soup". I can clearly see it defines the area I want to

Re: [Tutor] Calculating and returning possible combinations of elements from a given set

2010-07-28 Thread Dave Angel
ZUXOXUS wrote: My doubt now is whether I can change the way python show the combinations. I mean, here's what python actually does: for prod in itertools.product('abc', repeat=3): print(prod) ('a', 'a', 'a') ('a', 'a', 'b') ('a', 'a', 'c') ('a', 'b', 'a') ('a', 'b', 'b') ('a', '

Re: [Tutor] Plugin system - how to manage plugin files?

2010-07-28 Thread Scott Nelson
On Wed, Jul 28, 2010 at 10:07 AM, Mac Ryan wrote: > Hi everybody, > > Mac, I don't know if this is exactly what you are after, but I created a poor-man's plugin system by simply putting .py files into the same directory as my app and naming them like _plugin.py Each of these .py "plugins",

Re: [Tutor] Newbie question - syntax - BeautifulSoup

2010-07-28 Thread Tommy Kaas
-Oprindelig meddelelse- Fra: tutor-bounces+tommy.kaas=kaasogmulvad...@python.org [mailto:tutor-bounces+tommy.kaas=kaasogmulvad...@python.org] På vegne af Alan Gauld Sendt: 28. juli 2010 20:00 Til: tutor@python.org Emne: Re: [Tutor] Newbie question - syntax - BeautifulSoup "Tommy Kaas" wr

[Tutor] A Django Beginner View Question

2010-07-28 Thread Alasdair Macmillan
Hi I am building my first Django site which has a lot of effectively 'static' pages where I just want to make the meta data and text editable. The model is models.py class About(models.Model): page_title = models.CharField(max_length=900, help_text='Text at top of browser window') met

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 6:11 AM, Evert Rol wrote: > Sorry, forgot to reply-to-all: > > > I don't know the book nor the exercise, but see my comments interspersed in > the code, and a few general remarks at the bottom > >> From a practice exercise in Building Skills In Python page 64 I'm >> workin

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 6:19 AM, Hugo Arts wrote: > On Wed, Jul 28, 2010 at 11:41 AM, David Hutto wrote: >> From a practice exercise in Building Skills In Python page 64 I'm >> working on How Much Does The Atmosphere Weigh? Part 1: >> To check it states that the answer should be app. 10**18kg How

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Eike Welk
Hello David! On Thursday July 29 2010 01:00:15 David Hutto wrote: > but as a quick question, why does: > >>> 5e18 == 5**18 > > False 5e18 is a short form of a somewhat complex term: 5e18 == 5 * 10**18 == 500 But 5**18 is just the exponentiation operator: 5**18 == 38146972656

Re: [Tutor] Plugin system - how to manage plugin files?

2010-07-28 Thread Mac Ryan
On Wed, 2010-07-28 at 13:53 -0500, Scott Nelson wrote: > On Wed, Jul 28, 2010 at 10:07 AM, Mac Ryan > wrote: > Hi everybody, > > > Mac, > > I don't know if this is exactly what you are after, but I created a > poor-man's plugin system by simply putting .py files into the same >

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Hugo Arts
On Thu, Jul 29, 2010 at 1:10 AM, David Hutto wrote: > I get this with yours and Evert's modification from mult to div, but > if you're right, then the 10e18 the book states as a checker is a > typo/error. > Wait.. in your original e-mail you said the answer as given by the book was 10**18, not 10

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 7:35 PM, Hugo Arts wrote: > On Thu, Jul 29, 2010 at 1:10 AM, David Hutto wrote: >> I get this with yours and Evert's modification from mult to div, but >> if you're right, then the 10e18 the book states as a checker is a >> typo/error. >> > > Wait.. in your original e-mail

Re: [Tutor] Newbie question - syntax - BeautifulSoup

2010-07-28 Thread Alan Gauld
"Tommy Kaas" wrote > > for row in soup('table', {'class' : 'spad'})[0].tbody('tr'): > >Do you understand the syntax from a Python point of view? No. That's the problem. OK, I'll assume you understand the basic for loop structure and focus on the function call: soup('table', {'class' : 'spa

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Dave Angel
David Hutto wrote: I'll probably ending up reading something about it later in the book, but as a quick question, why does: 5e18 =5**18 False int(5e18) =int(5**18) False 1.01325e5 =1.01325**5 False The 999e44 notation is intended to be similar t

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 8:03 PM, Dave Angel wrote: > > > David Hutto wrote: >> >> >> I'll probably ending up reading something about it later in the book, >> but as a quick question, why does: >> >> > > 5e18 =5**18 > >> >> False >> > > int(5e18) =int(5**18) > >> >> False >

Re: [Tutor] Problem with input() and unicode string

2010-07-28 Thread Mark Tolonen
"Alan Gauld" wrote in message news:i2pqps$fp...@dough.gmane.org... "Alex" wrote The first print statement works as expected, both in IDLE and when double-clicking the file for a console view. The second one works in IDLE, but just flashes by when double-clicking the file, due to an error

[Tutor] Python Help - How to end program

2010-07-28 Thread Jason MacFiggen
Python keeps looping when it gets past the int 0, how do I end the program when it the int 0 or > 0. my_hp = 50 mo_hp = 50 my_dmg = random.randrange(1, 20) mo_dmg = random.randrange(1, 20) endProgram = end() while True: if mo_hp < 0: print "The Lich King has

Re: [Tutor] Python Help - How to end program

2010-07-28 Thread Benjamin Castillo
Jason   Are you trying to prevent negative numbers?   Ben --- On Wed, 7/28/10, Jason MacFiggen wrote: From: Jason MacFiggen Subject: [Tutor] Python Help - How to end program To: tutor@python.org Date: Wednesday, July 28, 2010, 9:01 PM Python keeps looping when it gets past the int 0, how do

Re: [Tutor] Python Help - How to end program

2010-07-28 Thread Mark Tolonen
"Jason MacFiggen" wrote in message news:aanlktinevw8zje7fxktomks+tbrp=trmb7sb7pbkt...@mail.gmail.com... Python keeps looping when it gets past the int 0, how do I end the program when it the int 0 or > 0. my_hp = 50 mo_hp = 50 my_dmg = random.randrange(1, 20) mo_dmg = random.randrang