[Tutor] put?

2008-05-01 Thread Ross Glover
Hi, I'm just learning python (as a first language) and I wrote this 
little snippet (cribbed from a website).  I'm wondering what 'put' is 
and how it's used.  I cannot seem to find much about it.



word = raw_input("enter your word >>")
put, get=os.popen4("dict -d wn " + (word))
for lines in get.readlines():
print lines


thanks,

ross

--
If you know what you're doing, you must not be 'doing' a dissertation.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] put?

2008-05-01 Thread Kent Johnson
On Thu, May 1, 2008 at 3:51 AM, Ross Glover <[EMAIL PROTECTED]> wrote:
> Hi, I'm just learning python (as a first language) and I wrote this little
> snippet (cribbed from a website).  I'm wondering what 'put' is and how it's
> used.  I cannot seem to find much about it.
>
>
> > word = raw_input("enter your word >>")
> > put, get=os.popen4("dict -d wn " + (word))
> > for lines in get.readlines():
> >print lines

put and get are variables that receive the result of the call to
popen4(). The docs for popen4() are here:
http://docs.python.org/lib/os-newstreams.html#os-newstreams

It says popen4() "returns the file objects (child_stdin,
child_stdout_and_stderr)", so put is linked to stdin for the child
process.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unsubscribtion

2008-05-01 Thread Kriti Satija
Please unsubscribe my membership from python tutorlist.


  Bring your gang together. Do your thing. Find your favourite Yahoo! group 
at http://in.promos.yahoo.com/groups/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] send and receive HTTP POST

2008-05-01 Thread shawn bright
Thanks, sorry i was late getting back to you, but gmail thought this
was spam. Go figure.
Anyway, SOAPpy is doing great. Thanks

shawn

On Wed, Apr 30, 2008 at 2:05 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> >  POST /soap/SMS.asmx HTTP/1.1
>  >  Host: api.upsidewireless.com
>  >  Content-Type: text/xml; charset=utf-8
>  >  Content-Length: length
>  >  SOAPAction: "http://upsidewireless.com/webservice/sms/Send_Plain";
>
>  It looks like you need SOAPpy:
>  http://diveintopython.org/soap_web_services/
>
>  Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unsubscribtion

2008-05-01 Thread Evans Anyokwu
Kriti,

You can unsubscribe yourself without waiting for anyone to do it for you.

Follow this link http://mail.python.org/mailman/listinfo/tutor
Bye.

Evans
http://www.javawug.org


On Thu, May 1, 2008 at 2:00 PM, Kriti Satija <[EMAIL PROTECTED]>
wrote:

> Please unsubscribe my membership from python tutorlist.
>
>
>  Bring your gang together. Do your thing. Find your favourite Yahoo!
> group at http://in.promos.yahoo.com/groups/
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unsubscribtion

2008-05-01 Thread bob gailer

Kriti Satija wrote:

Please unsubscribe my membership from python tutorlist.

  

Only you can do that. Visit http://mail.python.org/mailman/listinfo/tutor


--
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] put?

2008-05-01 Thread Alan Gauld


"Ross Glover" <[EMAIL PROTECTED]> wrote

Hi, I'm just learning python (as a first language) and I wrote this 
little snippet (cribbed from a website).  I'm wondering what 'put' 
is and how it's used.


Hmmm. It sounds like you may be jumping in too deep too soon.
Do you understand about files yet? Or variables?
Are you comfortable with the concepts of stdin asnd stdout?
If not you should probably stick to some of the more basic
material until you understand those ideas.

OTOH, if you are happy with those ideas:


word = raw_input("enter your word >>")
put, get=os.popen4("dict -d wn " + (word))
for lines in get.readlines():
print lines


put and get are the return values from popen and correspond
to stdin and stdout for the OS command inside popen().

get is the output of the command so the for loop prints
the results of the command. Its a rather long-winded
example IMHO.

But it depends where you found it and what exactly it was 
illustrating!


HTH


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] put?

2008-05-01 Thread Marc Tompkins
On Thu, May 1, 2008 at 12:51 AM, Ross Glover <[EMAIL PROTECTED]> wrote:

> put, get=os.popen4("dict -d wn " + (word))
>
> Something that can be a little confusing at first (and I haven't seen
anybody mention it yet, so I thought I'd chime in) is that you can assign
multiple variables at the same time.  It can be a little jarring if you
aren't used to it.  So far you've probably only run into single
assignments:  x=5, dog=cat, etc.
In contrast, this line runs a command that returns two values, and assigns
those values to two variables called "put" and "get".
If you weren't aware that multiple assignments were possible (and that this
is what they look like), then this is a very confusing line of code indeed.


Also - no offense to whoever put up the code you're learning from, but those
variable names were poorly chosen!  Since you're just starting out, you have
the opportunity to learn good habits early.  Don't use verbs as variable
names!  It is almost guaranteed to confuse the heck out of anybody who has
to read your code later - maybe even yourself, if you don't look at it
often.
Variable naming conventions are a very contentious topic - you'll get
fanatical supporters of "x" and "y", or Hungarian notation, or
"VeryDescriptiveVariableName", or whatever, and I'm not going to make an
endorsement... but I would make two hard and fast rules:
-  Don't use variable names that conflict with reserved words, e.g. don't
create a list variable and name it "list".
-  Don't use variable names that SOUND like they might conflict with
reserved words - like "put" and "get".



-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to skip to next line in for loop

2008-05-01 Thread Brain Stormer
I have the following code:

f = open('file.txt',r)
for line in f.read():
 if line == "3":
   line.next
   print line
f.close()

The file.txt looks like
1
2
3
4
5

I would like the code to output "4"

but I don't know how to use the next.  Are there any other way?

Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to skip to next line in for loop

2008-05-01 Thread Kent Johnson
On Thu, May 1, 2008 at 5:04 PM, Brain Stormer <[EMAIL PROTECTED]> wrote:
> I have the following code:
>
> f = open('file.txt',r)
> for line in f.read():
>  if line == "3":
>line.next

Try
  f.next()

line is a string, it doesn't have a next() method. The file itself is
iterable and has next(). Don't forget the parentheses!

Kent

>print line
> f.close()
>
> The file.txt looks like
> 1
>  2
> 3
> 4
> 5
>
> I would like the code to output "4"
>
> but I don't know how to use the next.  Are there any other way?
>
> Thanks
>
>
>
>
> ___
>  Tutor maillist  -  Tutor@python.org
>  http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unsubscribtion

2008-05-01 Thread ionut cucu


Here's how to unsubscribe:

First, ask your Internet Provider to mail you an Unsubscribing Kit.
Then follow these directions.

The kit will most likely be the standard no-fault type. Depending on
requirements, System A and/or System B can be used. When operating
System A, depress lever and a plastic dalkron unsubscriber will be
dispensed through the slot immediately underneath. When you have
fastened the adhesive lip, attach connection marked by the large "X"
outlet hose. Twist the silver-coloured ring one inch below the
connection point until you feel it lock.

The kit is now ready for use. The Cin-Eliminator is activated by the
small switch on the lip.  When securing, twist the ring back to its
initial condition, so that the two orange lines meet.  Disconnect.
Place the dalkron unsubscriber in the vacuum receptacle to the rear.
Activate by pressing the blue button.

The controls for System B are located on the opposite side. The red
release switch places the Cin-Eliminator into position; it can be
adjusted manually up or down by pressing the blue manual release
button. The opening is self-adjusting. To secure after use, press the
green button, which simultaneously activates the evaporator and
returns the Cin-Eliminator to its storage position.

You may log off if the green exit light is on over the evaporator.  If
the red light is illuminated, one of the Cin-Eliminator requirements
has not been properly implemented. Press the "List Guy" call button on
the right of the evaporator. He will secure all facilities from his
control panel.

To use the Auto-Unsub, first undress and place all your clothes in the
clothes rack. Put on the velcro slippers located in the cabinet
immediately below. Enter the shower, taking the entire kit with
you. On the control panel to your upper right upon entering you will
see a "Shower seal" button. Press to activate. A green light will then
be illuminated immediately below. On the intensity knob, select the
desired setting. Now depress the Auto-Unsub activation lever. Bathe
normally.

The Auto-Unsub will automatically go off after three minutes unless
you activate the "Manual off" override switch by flipping it up. When
you are ready to leave, press the blue "Shower seal" release
button. The door will open and you may leave. Please remove the velcro
slippers and place them in their container.

If you prefer the ultrasonic log-off mode, press the indicated blue
button. When the twin panels open, pull forward by rings A & B. The
knob to the left, just below the blue light, has three settings, low,
medium or high. For normal use, the medium setting is suggested.

After these settings have been made, you can activate the device by
switching to the "ON" position the clearly marked red switch. If
during the unsubscribing operation you wish to change the settings,
place the "manual off" override switch in the "OFF" position. You may
now make the change and repeat the cycle. When the green exit light
goes on, you may log off and have lunch. Please close the door behind
you.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problems sending POST data

2008-05-01 Thread Alex Krycek
Hello all,

I've been trying to send POST data to this library database with Python's
urllib, but I can't get it to work.

The website is
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?getLimitedTerms+2307(although
the session expires after a short period of time. So it's better
to first go to denverlibrary.org and then navigate to the advanced search
page).

This is the script that I used:

###
import urllib

queryString =
"database=10&search1=%2F%2Fw&terms1=&bool1=and&search2=%2F%2Fn&terms2=&bool2=and&search3=%2F%2Ftw%2F&terms3=nanking&bool3=and&search4=%2F%2Fsd%2F&terms4=&bool4=and&search5=%2F%2Fed%2F&terms5=&spellcheck=false&keywords1=qdvds&keywords2=--none--&datelimit=%3E&year1=&year2=&limiter_count=3&branch=&Search=Search&Available=yes"

url = "
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?customSearchFinish+17410";

print urllib.urlopen(url, queryString).read()
###

However, whenever I run the script I receive the page I was on (Advanced
Search page) again. I'd like to get the page with the search results. This
is what I got from livehttpheaders when I initiated a search from the
website:

###
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?customSearchFinish+17410

POST /cgi-bin/cw_cgi?customSearchFinish+17410 HTTP/1.1
Host: catalog.denverlibrary.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b5)
Gecko/2008032620 Firefox/3.0b5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer:
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?getLimitedTerms+17410
Cookie: __utma=109436176.390208191.1209600128.1209671991.1209676393.6;
__utmz=109436176.1209600128.1.1.utmccn=(referral)|utmcsr=
catalog.denverlibrary.org|utmcct=/cgi-bin/cw_cgi|utmcmd=referral;
__utma=125080728.808666458.1209606982.1209606982.1209606982.1;
__utmz=125080728.1209606982.1.1.utmccn=(referral)|utmcsr=denverlibrary.org|utmcct=/catalogs/index.html|utmcmd=referral;
__utmc=109436176; __utmb=109436176
Content-Type: application/x-www-form-urlencoded
Content-Length: 322
database=10&search1=%2F%2Fw&terms1=&bool1=and&search2=%2F%2Fn&terms2=&bool2=and&search3=%2F%2Ftw%2F&terms3=nanking&bool3=and&search4=%2F%2Fsd%2F&terms4=&bool4=and&search5=%2F%2Fed%2F&terms5=&spellcheck=false&keywords1=qdvds&keywords2=--none--&datelimit=%3E&year1=&year2=&limiter_count=3&branch=&Search=Search&Available=yes

HTTP/1.x 302 Found
Date: Thu, 01 May 2008 21:13:54 GMT
Server: Apache/2.2.0 (Unix) DAV/2 mod_ssl/2.2.0 OpenSSL/0.9.8b PHP/5.1.6
JRun/4.0
Location:
http://catalog.denverlibrary.org:80/cgi-bin/cw_cgi?resultsScreen+17410+1+1+0
Content-Length: 260
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
###

I'd appreciate any suggestions. Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] put?

2008-05-01 Thread bob gailer

Marc Tompkins wrote:
On Thu, May 1, 2008 at 12:51 AM, Ross Glover <[EMAIL PROTECTED] 
> wrote:


put, get=os.popen4("dict -d wn " + (word))

Something that can be a little confusing at first (and I haven't seen 
anybody mention it yet, so I thought I'd chime in) is that you can 
assign multiple variables at the same time.  It can be a little 
jarring if you aren't used to it.  So far you've probably only run 
into single assignments:  x=5, dog=cat, etc.

In contrast, this line runs a command that returns two values


No No. Python does not have "commands" and can't therefore "run" them.

A better way to express that is: on the right of the = is an expression 
which Python evaluates.
, and assigns those values to two variables called "put" and "get". 
If you weren't aware that multiple assignments were possible (and that 
this is what they look like), then this is a very confusing line of 
code indeed.



Also - no offense to whoever put up the code you're learning from, but 
those variable names were poorly chosen!  Since you're just starting 
out, you have the opportunity to learn good habits early.  Don't use 
verbs as variable names!  It is almost guaranteed to confuse the heck 
out of anybody who has to read your code later - maybe even yourself, 
if you don't look at it often. 
Variable naming conventions are a very contentious topic - you'll get 
fanatical supporters of "x" and "y", or Hungarian notation, or 
"VeryDescriptiveVariableName", or whatever, and I'm not going to make 
an endorsement... but I would make two hard and fast rules:
-  Don't use variable names that conflict with reserved words, e.g. 
don't create a list variable and name it "list". 
-  Don't use variable names that SOUND like they might conflict with 
reserved words - like "put" and "get".



 
--

www.fsrtechnologies.com 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  



--
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to skip to next line in for loop

2008-05-01 Thread bob gailer

Brain Stormer wrote:

I have the following code:

f = open('file.txt',r)
for line in f.read():


That will read the entire file into a string, then access one character 
at a time from the string.


If you want to work with lines:

for line in f:


  if line == "3":


Assuming you adopt my approach, then each line will  be a digit followed 
by \n (newline). So no line will == "3". Instead use:


   if line[:-1] == "3":


   line.next



Since next is a method it must be called, so that becomes:

   line.next()

The rest is fine.

   print line
f.close()

The file.txt looks like
1
2
3
4
5

I would like the code to output "4"

but I don't know how to use the next.  Are there any other way?


--
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unsubscribtion

2008-05-01 Thread bob gailer
That sounds like irony. Somehow not suitable for this list or for 
someone seeking help as to how to unsubscribe.


--
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to skip to next line in for loop

2008-05-01 Thread Alan Gauld


"Brain Stormer" <[EMAIL PROTECTED]> wrote 


f = open('file.txt',r)
for line in f.read():


This reads the whole file inta a string then iterates 
over all the characters(not lines) in that string.


Better to iterate over the file:

for line in f:



if line == "3":
  line.next


this then becomes f.next()  # next is a method not 
an attribute so needs the () to call it



--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to skip to next line in for loop

2008-05-01 Thread Alan Gauld


"bob gailer" <[EMAIL PROTECTED]> wrote


  if line == "3":


Assuming you adopt my approach, then each line will  be a digit 
followed by \n (newline). So no line will == "3". Instead use:


   if line[:-1] == "3":


or

if line.rstrip() == "3"

or even

   if line.startswith("3"):

personally I prefer rstrip() over the -1 slice because it catches
more potential junk.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems sending POST data

2008-05-01 Thread Kent Johnson
On Thu, May 1, 2008 at 6:02 PM, Alex Krycek <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I've been trying to send POST data to this library database with Python's
> urllib, but I can't get it to work.

It looks like the library server wants to set a cookie in your browser
and also responds with at redirect. I don't think urllib will handle
either of those. Look at this page:
http://personalpages.tds.net/~kent37/kk/00010.html
for some tips on how to use urllib2 to handle cookies.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] put? and files

2008-05-01 Thread Ross Glover
Thanks all for your in[put].  It did take me a minute to figure out that 
2 variables could get assigned using this method.  Thanks to your help, 
I managed to cobble together a fully functional GUI based dictionary 
program (MY FIRST!). 

That said, it would seem that I do need to understand files better.  
Does anyone have a suggestion for a solid and detailed explanation?  
Either online or a book?


What I want to do is write a program that parses text based on tags that 
I create, writes the text into separate files based on specified tags, 
i.e. each tag gets its own file.  At least this is my starting goal.


I've been working through the book Beginning Python, and I also went 
through AByteOfPython.  Slowly it's beginning to make sense, but I would 
very much like to know what my next best step should be given the above 
mentioned goal.  Text processing still eludes my understanding.


Thanks again,

ross

--
If you know what you're doing, you must not be 'doing' a dissertation.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] put?

2008-05-01 Thread Marc Tompkins
On Thu, May 1, 2008 at 4:02 PM, bob gailer <[EMAIL PROTECTED]> wrote:

> Marc Tompkins wrote:
> >
> > In contrast, this line runs a command that returns two values
> >
>
> No No. Python does not have "commands" and can't therefore "run" them.
>
> A better way to express that is: on the right of the = is an expression
> which Python evaluates.


a)  Yes, of course, you're right, my semantics were all wrong.  Serves me
right for ranting before finishing my coffee.

b)  However, you're being a bit dogmatic, dontcha think?  From the
documentation:
*popen*( command[, mode[, bufsize]]) Open a pipe to or from command. The
return value is an open file object connected to the pipe, which can be read
or written depending on whether mode is 'r' (default) or 'w'. The
bufsizeargument has the same meaning as the corresponding argument to
the built-in
open() function. The exit status of the command (encoded in the format
specified for wait()) is available as the return value of the close() method
of the file object, except that when the exit status is zero (termination
without errors), None is returned. Availability: Macintosh, Unix, Windows.

The subprocess module provides more powerful facilities for spawning new
processes and retrieving their results; using that module is preferable to
using this function.

Changed in version 2.0: This function worked unreliably under Windows in
earlier versions of Python. This was due to the use of the _popen() function
from the libraries provided with Windows. Newer versions of Python do not
use the broken implementation from the Windows libraries.
Ease up, Bob.


-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor