Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread spir

On 01/27/2014 06:04 PM, Denis Heidtmann wrote:

Apparently a[0]=b[0] does not qualify as "symbolic assignment" in this
case. a[0] is not a reference to b[0].  I think I see the essential
distinction.  Experience will complete the picture for me.


"symolic assignment" is my term, so whatever I mean with it qualifies as 
symbolic assignment ;-); and tes, your example a[0]=b[0] is indeed a symbolic 
assignment (because the right side "b[0]" denotes a value, an object, and could 
be on the left side of an assignment)
the distinction between "replacement" & "modification" also uses my terms; 
better you know that because if you talk with programmers using these terms as 
key words, others will be surprised


The real point is: maybe read again my previous post. I insisted on the fact 
that in python _symbols_ are not corelated, never ever. Your remark here seems 
to show that you expect a[0] and b[0] to be corelated, in such a way that if we 
change one of them the second should follow. No. Values are made unique by 
symbolic assignment; but this can only show if you modify them partly (not 
replace globally), thus can only show if those are complex values.



a = [1, [1,2]]
b = a
b

[1, [1, 2]]

b is a

True

a's and b's values are a single, unique object... as long as I only modifie them 
(the values) partly:



a = [1,[2,3]]
a[0] = 0
b

[0, [1, 2]]

a[1] = [0,0]
b

[0, [0, 0]]

a is b

True


a[0] = b[0]
a[0] is b[0]

True

Here i make their first elements the same unique value. But I'm blocked to show 
it (other than using 'is') because I cannot modify such objects (they are simple 
numbers). Since it is the _values_ which are related, not the symbols, if I 
replace one of them I break the relation.



a[0] = 9
a

[9, [2, 3]]

b

[1, [0, 0]]

Right? On the other, if I create a relatoin between their second elements, then 
I can have something more interesting:



a[1] = b[1]
a[1] is b[1]

True

a, b

([9, [0, 0]], [1, [0, 0]])

a[1][1] = 9
b[1][1]

9

a, b

([9, [0, 9]], [1, [0, 9]])

You will get used to it... Also, it just works most of the time, except for 
corner cases where you will be trapped 2-3 times until you get it. (The reason 
is that unconsciously, when we want several symbols to have their proper values, 
we just do it right by assigning them apart, even if they (initially) have the 
same values. When instead we want a symbol to refer to the same value as 
another, we correctly use a symbolic assignment; instead of incorrectly 
assigning an equal, but distinct, value.]


denis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Coordinates TK and Turtle

2014-01-28 Thread Ian D
Hello 

I have some weird results when I run my code which is meant to display a canvas 
and a turtle and some text with the turtles coordinates. 

Basically the turtle coordinates do not seem to correspond with the TK 
create_text coordinates. 


t1.goto(100,100) 

canvas_id = cv1.create_text(t1.xcor(), t1.ycor(), 
font=("Purisa",12),anchor="nw") 

cv1.insert(canvas_id, 0, t1.pos()) 

I end up with this output: 
http://i1025.photobucket.com/albums/y319/duxbuz/coord-issues_zps1fca6d2b.jpg 

Could anyone help please? 

Thanks___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coordinates TK and Turtle

2014-01-28 Thread eryksun
On Tue, Jan 28, 2014 at 4:48 AM, Ian D  wrote:
>
> I have some weird results when I run my code which is meant to display a
> canvas and a turtle and some text with the turtles coordinates.
>
> Basically the turtle coordinates do not seem to correspond with the TK
> create_text coordinates.
>
> t1.goto(100,100)
>
> canvas_id = cv1.create_text(t1.xcor(), t1.ycor(),
> font=("Purisa",12),anchor="nw")
>
> cv1.insert(canvas_id, 0, t1.pos())

A turtle has a `write` method:

http://docs.python.org/2/library/turtle#turtle.write

It sets up for undoing the operation, and then it has the screen write
on the Tk canvas. Here's the screen's `_write` method:

>>> print inspect.getsource(turtle.TurtleScreen._write)
def _write(self, pos, txt, align, font, pencolor):
"""Write txt at pos in canvas with specified font
and color.
Return text item and x-coord of right bottom corner
of text's bounding box."""
x, y = pos
x = x * self.xscale
y = y * self.yscale
anchor = {"left":"sw", "center":"s", "right":"se" }
item = self.cv.create_text(x-1, -y, text = txt,
   anchor = anchor[align],
   fill = pencolor, font = font)
x0, y0, x1, y1 = self.cv.bbox(item)
self.cv.update()
return item, x1-1

xscale and yscale should be 1.0, but maybe not if you've called
`setworldcoordinates`. The y coordinate has to be negated, since it
increases from top to bottom in the canvas. I don't know about the -1
offset for the x coordinate. Scanning over the source, I don't see a
similar offset used for drawing lines, polygons, and images. So I
guess it's something to do with how `create_text` works. But I'm far
from being an expert with Tk widgets.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Importing Pygame

2014-01-28 Thread myles broomes
I am trying to import pygame but everytime I do, I get an ImportError. Here is 
the code I'm trying to run:

import pygame,sys
from pygame.locals import *

pygame.init()
DISPLAYSURF=pygame.display.set_mode((400,300))
pygame.display.set_caption('Hello World!')
while True: #main game loop
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
pygame.display.update()

And the error I get:

Traceback (most recent call last):
  File "C:\Python32\blankgame.py", line 1, in 
import pygame,sys
ImportError: No module named 'pygame'

When I import pygame using the shell however, it works fine. I am using Python 
3.2.3 and the Pygame installer I downloaded is pygame-1.9.2a0.win32-py3.2.msi.  
   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Importing Pygame

2014-01-28 Thread Dave Angel
 myles broomes  Wrote in message:
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

I'm guessing you're attempting to post here in this text newsgroup
 using html. Please use text. It's a pain to quote your message
 when none of it shows.

> And the error I get:

Traceback (most recent call last):
  File "C:\Python32\blankgame.py", line 1, in 
    import pygame,sys
ImportError: No module named 'pygame'

When I import pygame using the shell however, it works fine. I am
 using Python 3.2.3 and the Pygame installer I downloaded is
 pygame-1.9.2a0.win32-py3.2.msi.


Please be as specific as possible.  Apparently you're running
 Windows and when you run your Python script from a cmd shell, the
 import works fine, but when you run it some other unspecified
 way, you get the import error.  You could learn a lot by printing
 sys.path, the search path for import.

My guess is that you have two different installs of python, and
 some difference in how you're launching the script is invoking
 the different installations.

While you're investigating,  please move your blankgame script
 somewhere that's NOT in the installation directory.  You'll only
 confuse things when some things happen to sortof
 work.



-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread Denis Heidtmann
On Tue, Jan 28, 2014 at 12:28 AM, spir  wrote:

> 
>
>  a = [1, [1,2]]
 b = a
 b

>>> [1, [1, 2]]
>
>> b is a

>>> True
>
> a's and b's values are a single, unique object... as long as I only
> modified them (the values) partly:
>
>  a = [1,[2,3]]
 a[0] = 0
 b

>>> [0, [1, 2]]  # this is where I get lost.
>
>> a[1] = [0,0]
 b

>>> [0, [0, 0]]
>
>> a is b

>>> True
>
>  a[0] = b[0]
 a[0] is b[0]

>>> True
> 
>
> denis



My python gets a different result:

 >>> a=[1,[1,2]]
>>> b=a
>>> b
[1, [1, 2]]
>>> a=[1,[2,3]]  # this breaks the connection.
>>> a[0]=0
>>> b
[1, [1, 2]]
>>> a[1]=[0,0]
>>> b
[1, [1, 2]]
>>>

What is going on?  I am more confused than I was a week ago.

-Denis H
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Installing Python on osx 10.9.1

2014-01-28 Thread Aubri Sandlin
I have installed Python.  When I open IDLE I get this warning:  >>> WARNING: 
The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.


I have downloaded and installed the latest version of TCL/TK and rebooted my 
computer.  I still get the above warning.  

What else do I need to do in order to be able to use Python?


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] subprocess.Popen help

2014-01-28 Thread leam hall
Python tutorial for 2.6 (using 2.4 -- don't ask), first code blurb under 17.1.1

http://docs.python.org/2.6/library/subprocess.html?highlight=subprocess#subprocess.Popen

How would you make an ssh to another box put data back in "p"? The
goal is to run a shell command on a remote box and work with the
output on the local host.

Thanks!

Leam

-- 
Mind on a Mission
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Can't figure out why I'm getting no output??

2014-01-28 Thread scurvy scott
Hey all.. First of all here is my code:

import requests
from bs4 import BeautifulSoup as beautiful


payload = {'username': 'X', 'password': 'XX'}
r = requests.post("http://dogehouse.org/index.php?page=login";, data=payload)
soup = beautiful(r.text)
confirmed = str(soup.findAll('span',{'class':'confirmed'}))


print "Confirmed account balance" +confirmed[86:98]

I'm running it on Crunchbang/Debian Linux

I'm trying to write a basic scraper that I can use to output my current
account balance from my mining pool in my terminal.
I've tested the code in the regular python interpreter and it all executes
the way it should. But when I attempt to run it using "python whatever.py"
it doesn't give me any output. Any tips would be appreciated. Thanks.

scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Importing Pygame

2014-01-28 Thread Glenn Lester
I think you typed a comma instead of a period when you coded import
pygame.sys
Or it may be my display. Check it out.

Best of Luck


On Tue, Jan 28, 2014 at 1:13 PM, myles broomes
wrote:

> I am trying to import pygame but everytime I do, I get an ImportError.
> Here is the code I'm trying to run:
>
> import pygame,sys
> from pygame.locals import *
>
> pygame.init()
> DISPLAYSURF=pygame.display.set_mode((400,300))
> pygame.display.set_caption('Hello World!')
> while True: #main game loop
> for event in pygame.event.get():
> if event.type==QUIT:
> pygame.quit()
> sys.exit()
> pygame.display.update()
>
> And the error I get:
>
> Traceback (most recent call last):
>   File "C:\Python32\blankgame.py", line 1, in 
> import pygame,sys
> ImportError: No module named 'pygame'
>
> When I import pygame using the shell however, it works fine. I am using
> Python 3.2.3 and the Pygame installer I downloaded 
> ispygame-1.9.2a0.win32-py3.2.msi.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


-- 

*Glenn Lester*

Software Tester

*Avant Systems Group*

*voice: *204.789.9596 x19 *|** fax: *204.789.9598 *|** email: *
gles...@avant.ca*|** web: *www.avant.ca



*Quality People Delivering Quality Solutions*

CONFIDENTIALITY NOTICE: This correspondence and any attachment(s) may
contain confidential information that is legally privileged. If you are not
the intended recipient, or the person responsible for delivering it, you
are hereby notified that any disclosure, copying, distribution or use of
any of the aforementioned information is STRICTLY PROHIBITED. If you have
received this transmission in error, please permanently delete the original
transmission and its attachments without reading or saving in any manner.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] If, elif, else

2014-01-28 Thread Michael L. Pierre
I am a newbie with Python (programming in general) and I am trying to create a 
program that will take user name and dob and pump out their age, while on a 
person's birthday the output not only states their name and age, but also 
prints out ***HAPPY BIRTHDAY***
I have gotten it resolved to the point that it understands leap  years and 
gives the correct age. My problem arises when a date is input that is the 
current month, but a future date (i.e. today's date is 1/28/2014 but the input 
dob is 1/30/1967) It skips over the elif option to subtract one year and prints 
out ***HAPPY BIRTHDAY***
I am only going to paste the non-leap year code, because the leap year code is 
basically identical.

#Leapyear calculations/decision
if leap_year != int:
age_month = int(current_split[1]) - int(dob_split[1])
#print age_month
if age_month != 0:
month_less = 1
age = int(current_split[0]) - int(dob_split[0]) - month_less
print "you are", age, "years old"
elif age_month == 0 and int(current_split[2]) > int(dob_split[2]):
age = int(current_split[0]) - int(dob_split[0]) - month_less
print "you are", age, "years old"
else:
   age = int(current_split[0]) - int(dob_split[0])
   print "You are", age, "and today is your birthday ***HAPPY BIRTHDAY***"

Any help would be greatly appreciated :)

Michael Pierre
CCPOA IT Specialist
916-372-6060 Ext. 221


__
California Correctional Peace Officers Association Notice of Confidentiality:
This email message, including any attachments, is for the sole use of
the intended recipient(s). These items may contain confidential and/or
privileged information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the intended recipient,
please contact the sender by reply email and destroy all copies of
the original message.
_
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] If, elif, else

2014-01-28 Thread Dave Angel
 "Michael L. Pierre"  Wrote in message:
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

Start by posting in text form, since this is a text group.  You
 apparently posted in html. And you doublespaced.
 

Any reason you didn't use the date module?  The code would have
 been much simpler. 

> gotten it resolved to the point that it understands leap  years and gives 
> the correct age. 

Sometimes. 

> My problem arises when a date is input that is the current month, but a 
> future date (i.e. today’s date is 1/28/2014 but the input dob is 1/30/1967)
 It skips over the elif option to subtract one year and prints out
 ***HAPPY BIRTHDAY***

> am only going to paste the non-leap year code, because the leap year code is 
> basically identical.

 Problems from a quick perusal.  

 The first if clause tries to handle the cases where the month is
 different.  But it should only be subtracting 1 if age_month is
 negative. 

Next the elif clause. You subtract month_less but don't initialize
 it to zero.  Why bother subtracting anyway? In this clause
 there's no adjustment needed.

Next the missing elif for int(current_split[2])  < int(dob_split[2]):


-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can't figure out why I'm getting no output??

2014-01-28 Thread Dave Angel
 scurvy scott  Wrote in message:
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

Please post as text, not html.

Try putting a print at the top of the code.  If it gets there and
 not to the last one, one of those lines is hanging.


-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] If, elif, else

2014-01-28 Thread spir

On 01/28/2014 11:46 PM, Michael L. Pierre wrote:

I am a newbie with Python (programming in general) and I am trying to create a 
program that will take user name and dob and pump out their age, while on a 
person's birthday the output not only states their name and age, but also 
prints out ***HAPPY BIRTHDAY***
I have gotten it resolved to the point that it understands leap  years and 
gives the correct age. My problem arises when a date is input that is the 
current month, but a future date (i.e. today's date is 1/28/2014 but the input 
dob is 1/30/1967) It skips over the elif option to subtract one year and prints 
out ***HAPPY BIRTHDAY***
I am only going to paste the non-leap year code, because the leap year code is 
basically identical.

#Leapyear calculations/decision
if leap_year != int:
 age_month = int(current_split[1]) - int(dob_split[1])
 #print age_month
 if age_month != 0:
 month_less = 1
 age = int(current_split[0]) - int(dob_split[0]) - month_less
 print "you are", age, "years old"
 elif age_month == 0 and int(current_split[2]) > int(dob_split[2]):
 age = int(current_split[0]) - int(dob_split[0]) - month_less
 print "you are", age, "years old"
 else:
age = int(current_split[0]) - int(dob_split[0])
print "You are", age, "and today is your birthday ***HAPPY BIRTHDAY***"

Any help would be greatly appreciated :)


This is not an answer to your question, just some notes (which may help for this 
issue and others). The number one problem in programming is certainly 
understandability, or clarity for short. Programming is very hard (and quality 
very low) because we have major problems to understand what the code *actually* 
means, even often our own code while we're at it (not to mention a few weeks 
later, or years). We should do our best to reduce complication and obscurity as 
much as possible (even to the point of reducing our ambitions in terms of scope 
or scale, functionality or sophistication).


* What about a comment explaining your logic here, also for yourself, in plain 
natural language? (obviously it's not obvious, firstly for yourself, else the 
bug would be obvious...)


* I cannot guess what "if leap_year != int" may mean. (But I note you know, 
apparently, that int is a python type and int() acts like a function producing 
an int value.)


* You are using items of multi-item data 'current_split' and 'dob_split' 
(probably tuples) as key elements in the control of your application logic: why 
about naming these elements after their *meaning*? This would make the flow 
control clear, your understanding better, and your debugging, modifications, 
maintenance far easier? eg for instance

year, month, day = current_split
[Or better create a Date type with year, month, day properties (or use python's, 
in the module datetime).]


* It's certainly acceptable to name something 'dob' in code (provided you 
comment it), but not in the text of a message on a mailing. (For whatever 
mysterious reason the meaning popped up in mind nevertheless, so _i_ don't need 
a translation anymore.)


* You don't need the "age_month == 0" sub-condition in the elif branch. (why?) 
(or your logic is wrong otherwise)


d
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Installing Python on osx 10.9.1

2014-01-28 Thread Dave Angel
 Aubri Sandlin  Wrote in message:
> I have installed Python.  When I open IDLE I get this warning:  >>> WARNING: 
> The version of Tcl/Tk (8.5.9) in use may be unstable.
> Visit http://www.python.org/download/mac/tcltk/ for current information.
> 
> 
> I have downloaded and installed the latest version of TCL/TK and rebooted my 
> computer.  I still get the above warning.  
> 
> What else do I need to do in order to be able to use Python?
>
> 
> 

IDLE isn't an integral part of python.  I've never tried it in
 about five years of using Python. 

But if you think you need it, then tell people what version of
 Python and what version of (mac?) operating system.
 

-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread Danny Yoo
Hi Denis,

Ok, stop for a moment.

Visit:http://pythontutor.com/visualize.html

Specifically, here's your program:


http://pythontutor.com/visualize.html#code=a%3D%5B1,%5B1,2%5D%5D%0Ab%3Da%0Aa%3D%5B1,%5B2,3%5D%5D%0Aa%5B0%5D%3D0%0Aa%5B1%5D%3D%5B0,0%5D&mode=display&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=2&curInstr=3


Step through it, and see if anything there makes sense.  :P

Try a few more simple programs there, including the examples discussed
earlier on this thread.

I have a feeling that your mental model of what's happening is not
quite matching the machine, so the visualizer at
http://pythontutor.com/visualize.html may help bridge that gap.



Good luck!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Installing Python on osx 10.9.1

2014-01-28 Thread Dave Angel
 Dave Angel  Wrote in message:
>  Aubri Sandlin  Wrote in message:
>> I have installed Python.  When I open IDLE I get this warning:  >>> WARNING: 
>> The version of Tcl/Tk (8.5.9) in use may be unstable.
>> Visit http://www.python.org/download/mac/tcltk/ for current information.
>> 
>> 
>> I have downloaded and installed the latest version of TCL/TK and rebooted my 
>> computer.  I still get the above warning.  
>> 
>> What else do I need to do in order to be able to use Python?
>>
>> 
>> 
> 
> IDLE isn't an integral part of python.  I've never tried it in
>  about five years of using Python. 
> 
> But if you think you need it, then tell people what version of
>  Python and what version of (mac?) operating system.
>  
Oops, I just noticed you give some of that information in the
 subject line. Sorry. 

But it'd be useful to know just what version of Tcl/Tj you tried
 to install.

You did realize that recent versions of os have a python
 installed,  like most systems other than Windows?
 


-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread Dave Angel
 Denis Heidtmann  Wrote in message:
>
> 
 What is going on?  I am more confused than I was a week ago.


Simple. spir has copy/paste editing errors. 

-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread Alan Gauld

On 28/01/14 19:00, Denis Heidtmann wrote:

On Tue, Jan 28, 2014 at 12:28 AM, spir 

This is getting confusing with two times Denis!


> wrote:

a = [1,[2,3]]


I think the above line is a mistake. If Denis(spir) had missed
this out his code would work as he describes, but with it he
reassigns 'a' to a new list and, as you say breaks the connection.

If you forget about that line and keep a pointing at the original 
[1,[1,2]] list then the following code makes sense.



a[0] = 0
b

[0, [1, 2]]  # this is where I get lost.

a[1] = [0,0]
b

[0, [0, 0]]




My python gets a different result:


So does mine, and I suspect so does denis' (spir).
I think he made a mistake with the second assignment to a.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] subprocess.Popen help

2014-01-28 Thread Alan Gauld

On 28/01/14 19:52, leam hall wrote:

Python tutorial for 2.6 (using 2.4 -- don't ask), first code blurb under 17.1.1

http://docs.python.org/2.6/library/subprocess.html?highlight=subprocess#subprocess.Popen

How would you make an ssh to another box put data back in "p"? The
goal is to run a shell command on a remote box and work with the
output on the local host.


How do you do it outside of Python?
There is no great magic in Popen, it just reads/writes the
standard streams.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can't figure out why I'm getting no output??

2014-01-28 Thread Alan Gauld

On 28/01/14 20:45, scurvy scott wrote:


import requests
from bs4 import BeautifulSoup as beautiful

payload = {'username': 'X', 'password': 'XX'}
r = requests.post("http://dogehouse.org/index.php?page=login";, data=payload)
soup = beautiful(r.text)
confirmed = str(soup.findAll('span',{'class':'confirmed'}))

print "Confirmed account balance" +confirmed[86:98]



I've tested the code in the regular python interpreter and it all
executes the way it should. But when I attempt to run it using "python
whatever.py" it doesn't give me any output.


Can you clarify what you mean by not giving any output?
Does the print statement print "Confirmed account balance"
with no further data? Or does it not even do that?

Does the OS prompt return? or does it just hang?
Are there any error messages, either from Python or from the OS?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Importing Pygame

2014-01-28 Thread Alan Gauld

On 28/01/14 20:47, Glenn Lester wrote:

I think you typed a comma instead of a period when you coded import
pygame.sys
Or it may be my display. Check it out.


No, it was deliberate. He was importing pygame *and* sys.
A comma separated import list is fine.

I agree with Dave it looks like there are two Python installs
fighting with each other somewhere. One has PyGame installed
the other doesn't (or can't see it).

But we need more details to be sure.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] If, elif, else

2014-01-28 Thread Alan Gauld

On 28/01/14 22:46, Michael L. Pierre wrote:

I am a newbie with Python (programming in general)


Welcome to the list.


I have gotten it resolved to the point that it understands leap  years
and gives the correct age.


OK, I'll believe you, at least for now... :-)


 My problem arises when a date is input that
is the current month, but a future date (i.e. today’s date is 1/28/2014
but the input dob is 1/30/1967)


I don;t understand that. How is 1967 a future date?
Do you just mean the fact that the day is bigger than todays day?


It skips over the elif option to
subtract one year and prints out ***HAPPY BIRTHDAY***


Unfortunately  its hard to tell exactly whats going on
because we can't see where much of the data comes from.
I'll make a few comments below but I'm not sure if they will help 
pinpoint your main issue.



if leap_year != int:


No idea what this is supposed to be doing?
It is comparing leap_year to a type object.
I doubt very much if this 'if' test ever fails.


 age_month = int(current_split[1]) - int(dob_split[1])


No idea what current_split or dob_split are. Since you are
converting them to int I'll assume string lists maybe?


 if age_month != 0:
 month_less = 1
 age = int(current_split[0]) - int(dob_split[0]) - month_less
 print "you are", age, "years old"

 elif age_month == 0 and int(current_split[2]) > int(dob_split[2]):
 age = int(current_split[0]) - int(dob_split[0]) - month_less


Note that you use month_less here even though you don't assign it a 
value as you did in the if block.

Does it already have a value or is that an oversight?


 print "you are", age, "years old"



 else:
age = int(current_split[0]) - int(dob_split[0])
print "You are", age, "and today is your birthday ***HAPPY
BIRTHDAY***"


I assume you haven't found the datetime module yet?
It will take much of the hassle of date/time calculations away.
Or maybe you are doing it the hard way as a learning exercise?
That's OK too. :-)

A final thought. It might be worth putting some debug print
statements in so you can see what the values in the tsts are.

eg just before the if block put

print 'age_month = ', age_month

Also instead of relying on arithmetic you could maybe create some 
intermediate values.

Instead of
int(current_split[0]) - int(dob_split[0])

being calculated twice store it as a value, maybe called 
month_difference or similar?


It all helps make the code clearer and therefore easier
to debug.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread spir

On 01/29/2014 02:10 AM, Dave Angel wrote:

  Denis Heidtmann  Wrote in message:




  What is going on?  I am more confused than I was a week ago.


Simple. spir has copy/paste editing errors.


Oops! sorry

d
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] subprocess.Popen help

2014-01-28 Thread eryksun
On Tue, Jan 28, 2014 at 2:52 PM, leam hall  wrote:
> Python tutorial for 2.6 (using 2.4 -- don't ask), first code blurb under 
> 17.1.1
>
> http://docs.python.org/2.6/library/subprocess.html?highlight=subprocess#subprocess.Popen
>
> How would you make an ssh to another box put data back in "p"? The
> goal is to run a shell command on a remote box and work with the
> output on the local host.

To run a single command via ssh, you may not need to script a fake tty
(as w/ pexpect). That's presuming you use the sshpass program or have
ssh-agent set up, along with keys created and copied by ssh-keygen and
ssh-copy-id.

from subprocess import Popen, PIPE

args = ['ssh', 'localhost', 'uname', '-o']
kwds = dict(stdout=PIPE, stderr=PIPE)
p = Popen(args, **kwds)



>>> p.wait()
0
>>> p.stdout.read()
'GNU/Linux\n'

To script an interactive shell more generally, you probably do want a
fake tty, such as pexpect with the pxssh module. Older versions will
work in Python 2.4. A more robust choice is Fabric, which uses the
Paramiko SSH2 library. But Fabric requires Python 2.5+.

http://pexpect.readthedocs.org
http://fabric.readthedocs.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor