Re: getting the status codes from the ftplib module

2005-12-29 Thread John J. Lee
Alvin A. Delagon [EMAIL PROTECTED] writes:

 I'm writing a simple python code that will upload files onto a ftp 
 server. Everything's fine and working great except that the script I 
 wrote don't know is an upload is successful or not. Is there a way to 
 obtain the ftp status codes with this module? Thanks in advance!

forgot to mention that the urllib2 example I posted is for Python 2.4
-- won't work with 2.3.

For 2.3, 2.2, and 2.1, you have to do:

import urllib2

try:
response = urllib2.urlopen(http://www.reportlab.com/blarney;)
except urllib2.HTTPError, e:
print e.code
else:
print 200


urllib2 in 2.0 is a bit broken, IIRC.


John

-- 
http://mail.python.org/mailman/listinfo/python-list


getting the status codes from the ftplib module

2005-12-28 Thread Alvin A. Delagon
I'm writing a simple python code that will upload files onto a ftp 
server. Everything's fine and working great except that the script I 
wrote don't know is an upload is successful or not. Is there a way to 
obtain the ftp status codes with this module? Thanks in advance!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting the status codes from the ftplib module

2005-12-28 Thread Fredrik Lundh
Alvin A. Delagon wrote:

 I'm writing a simple python code that will upload files onto a ftp
 server. Everything's fine and working great except that the script I
 wrote don't know is an upload is successful or not. Is there a way to
 obtain the ftp status codes with this module? Thanks in advance!

the module raises an exception if something fails.  if you didn't get
an exception, everything worked as expected.

most methods, including the storlines and storbinary methods, also
return the status code.

/F



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting the status codes from the ftplib module

2005-12-28 Thread Alvin A. Delagon




[EMAIL PROTECTED] wrote:

  Send Python-list mailing list submissions to
	python-list@python.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
	[EMAIL PROTECTED]

You can reach the person managing the list at
	[EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."
  
  

Today's Topics:

   1. Re: python bug in this list implementation? (Fredrik Lundh)
   2. Re: python coding contest (Bengt Richter)
   3. Re: python coding contest (Roman Susi)
   4. Re: sorting with expensive compares? (Stuart D. Gathman)
   5. Re: Timing out arbitrary functions (antti kervinen)
   6. Re: python coding contest (Duncan Booth)
   7. Re: Patch : doct.merge (Nicolas Lehuen)
   8. Re: [EVALUATION] - E04 - Leadership! Google, Guido van
  Rossum, PSF (Martin P. Hellwig)
   9. getting the status codes from the ftplib module (Alvin A. Delagon)
  10. Re: getting the status codes from the ftplib module
  (Fredrik Lundh)
  
  
  
  

  

Subject:

Re: python bug in this list implementation?
  
  

From: 
"Fredrik Lundh" [EMAIL PROTECTED]
  
  

Date: 
Wed, 28 Dec 2005 08:50:47 +0100
  
  

To: 
python-list@python.org
  

  
  

  

To: 
python-list@python.org
  

  
  
  Chris Smith wrote:

  
  
I've been working on some multi-dimensional lists and I've encountered some
very strange behaviour in what appears to be simple code, I'm using python
2.4.2 and IDLE. If anyone can tell me why it's behaving so strange please
let me know, any improvements to my general coding style are also
appreciated.
code below:

import sys
import copy

grid = []
oGrid = []
sGrid = []

def createGrid():
f = open(r"...sudoku.txt", "rb") ## see attached for the file.

for line in f:
aLine = line.strip().split(',')
if aLine != [""]:
for i in xrange(len(aLine)):
aLine[i] = int(aLine[i])
grid.append(aLine)

  
  
at this point, grid contains a list of lists.

  
  
oGrid = copy.deepcopy(grid)

  
  
if you assign to a name inside a function, that name is considered to be
*local*, unless you specify otherwise.  in other words, this doesn't touch
the *global* (module-level) oGrid variable.

  
  
sGrid.append(copy.deepcopy(grid))

  
  
here you add a list of lists to a list.  the result is a list with a single item.

  
  
def printGrid():
print "original grid:"
for line in oGrid:
print line#why doesn't this print anything?

  
  
because the *global* oGrid is still empty.

  
  
print "S grid:"
for line in sGrid:
print line  #this prints the grid but the formatting is all over the
place.

  
  
because sGrid contains a single item; a copy of your original grid.

  
  
print "Iteration grid: "
for line in grid:
print line  #works fine!

  
  
as expected.

I suggest reading up on list methods and global variables in your favourite
python tutorial.

also read:

http://www.catb.org/~esr/faqs/smart-questions.html#id3001405

/F




  
  
  
  

  

Subject:

Re: python coding contest
  
  

From: 
[EMAIL PROTECTED] (Bengt Richter)
  
  

Date: 
Wed, 28 Dec 2005 08:09:51 GMT
  
  

To: 
python-list@python.org
  

  
  

  

To: 
python-list@python.org
  

  
  
  On 27 Dec 2005 09:24:44 GMT, Duncan Booth [EMAIL PROTECTED] wrote:

  
  
Scott David Daniels wrote:



  
I definitively need a new algorythm. g


  
  And I am sadly stuck at 169.  Not even spitting distance from 149 (which
sounds like a non-cheat version).
  

Throw it away and start again with a fresh (clean) solution. That's what I 
did when I'd reached the limit of nested maps and lambdas at 150 
characters. I'm now on 134 characters and the solution is very nearly 
legible. (Frustratingly, I'm away for the next few days, so I may not get a 
chance to submit my solution).

It would be a nice idea to come up with a scoring system which better 
reflects Python's ideals. For example, use the parser in Python to count up 
various syntactic elements, score 0 for comments, indents, dedents, 
newlines, docstrings, 1 for each name or operation used and higher scores 
for things like lambda or overly complex expressions.

  
  
[23:28] C:\pywk\clp\seven\pycontest_01py24 test.py
.
--
Ran 1 test in 0.391s

OK

[23:28] C:\pywk\clp\seven\pycontest

Re: getting the status codes from the ftplib module

2005-12-28 Thread Alvin A. Delagon
I'm very sorry, newbie here! @_@ I'm still getting the hang of Thunderbird.
-- 
http://mail.python.org/mailman/listinfo/python-list