[Tutor] checking if data files are good, readable, and exist

2008-07-22 Thread Bryan Fodness
I would like to check to see if the data files are good, readable, and
exist.  I have checked to see if they exist, but their is a possibility that
the data file might be binary, and I would like to have a sys.exit for that
as well.

if not os.path.isfile(A_data) or not os.path.isfile(B_data)\
   or not os.path.isfile(C_data) or not os.path.isfile(D_data):
sys.exit(14)




-- 
The game of science can accurately be described as a never-ending insult to
human intelligence. - João Magueijo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] checking if data files are good, readable, and exist

2008-07-22 Thread Tim Golden

Bryan Fodness wrote:
I would like to check to see if the data files are good, readable, and 
exist.  I have checked to see if they exist, but their is a possibility 
that the data file might be binary, and I would like to have a sys.exit 
for that as well.


You're going to be asked a lot of questions along the lines
of What do you mean by binary?. I'm going to assume you
mean: has things other than ordinary letters, numbers
and punctuation in it. In today's internationalised and
Unicoded world that's a highly dodgy assumption, but I'm 
going to go with it.


To compound the crudeness of my approach, I'm going to
assume that anything  126 is binary (thus dodging
the more complicated issue of the 0-31 control chars).

code
def is_binary (filename):
 return any (ord (c)  126 for c in open (filename).read ())

print is_binary (file1.txt)

/code

Obviously, if you know any of the files is going to be
massive, you'll want to do something a bit smarter than
this.

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


[Tutor] %(value1, value2) what does this returns

2008-07-22 Thread vishwajeet singh
Hi List,

def __request(symbol, stat):
url = 'http://finance.yahoo.com/d/quotes.csv?s=%sf=%s' % (symbol, stat)
 return urllib.urlopen(url)

I want to know in this % (symbol, stat) returns

thanks for help

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


Re: [Tutor] %(value1, value2) what does this returns

2008-07-22 Thread Michiel Overtoom
Vishwajeet wrote...

 I want to know in this % (symbol, stat) returns

In itself it returns nothing.  The '%' is used as the 'string interpolation
operator' here.

http://docs.python.org/lib/typesseq-strings.html

 print %d kilos of %s for %f euro % (2,mangos,3.75)
2 kilos of mangos for 3.75 euro

Greetings,

-- 
The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing. - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

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


Re: [Tutor] %(value1, value2) what does this returns

2008-07-22 Thread vishwajeet singh
thanks to all of you for your responses;

On Wed, Jul 23, 2008 at 12:18 AM, Michiel Overtoom [EMAIL PROTECTED] wrote:

 Vishwajeet wrote...

  I want to know in this % (symbol, stat) returns

 In itself it returns nothing.  The '%' is used as the 'string interpolation
 operator' here.

 http://docs.python.org/lib/typesseq-strings.html

  print %d kilos of %s for %f euro % (2,mangos,3.75)
 2 kilos of mangos for 3.75 euro

 Greetings,

 --
 The ability of the OSS process to collect and harness
 the collective IQ of thousands of individuals across
 the Internet is simply amazing. - Vinod Vallopillil
 http://www.catb.org/~esr/halloween/halloween4.htmlhttp://www.catb.org/%7Eesr/halloween/halloween4.html

 ___
 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] %(value1, value2) what does this returns

2008-07-22 Thread bob gailer

vishwajeet singh wrote:

Hi List,

def __request(symbol, stat):
url = 'http://finance.yahoo.com/d/quotes.csv?s=%sf=%s 
http://finance.yahoo.com/d/quotes.csv?s=%sf=%s' % (symbol, stat)

 return urllib.urlopen(url)

I want to know in this % (symbol, stat) returns


Assume symbol = foo and stat = bar.
Then url = 'http://finance.yahoo.com/d/quotes.csv?s=foof=bar 
http://finance.yahoo.com/d/quotes.csv?s=%sf=%s


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

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


Re: [Tutor] checking if data files are good, readable, and exist

2008-07-22 Thread Alan Gauld

W W [EMAIL PROTECTED] wrote


Am I wrong in thinking that /all/ files are stored as binary?


No, thats quite right.


python opens them, it automagically opens them in a
more readable format,


But that isn't. Python just reads the data and interprets it
as text if you specify a text file - the default - or as raw data
if you use rb.

Python doesn't alter the data in any way it simply assumes
that its text and interprets the bytes according to the current
alphabet. Thus it reads the value 65 and interprets it as 'A'
(assuming ASCII) in text mode or just as the bit pattern
0101 in binary. The application must then interpret the
bits in whatever way it considers appropriate - ass an integer,
a bitmask, part of a graphic image etc.

The important point is that there is no distinction between
binary data or text data in the file itself its just how it is
interpreted that distinguishes them. (This is not completely
true on some OS where text files always have an EOF marker,
but it is itself just a binary value!)

None of which helps the OP other than to highlight the difficulty
of determining if a file in binary or not. We can sometimes
tell if a file is not text - if it uses ASCII - by looking at the 
range

of byte values, but thats sloowww... but we can never be
sure that a file is non text. (We can also check for common
file headers such as postscript, GIF, MP3, JPEG, MIDI, etc
etc but even they can be misleading if they just coincidentally
look valid)

HTH,

Alan G. 



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


Re: [Tutor] checking if data files are good, readable, and exist

2008-07-22 Thread bob gailer

Alan Gauld wrote:

But that isn't. Python just reads the data and interprets it
as text if you specify a text file - the default - or as raw data
if you use rb.


But it DOES handle line-ends in an OS independent manner. Windows uses 
CR-LF as a line end, whereas Unix, Linux, Mac use (just CR or is it LF?).


Python presents line-ends uniformly as \n when you open the file in text 
mode.


Witness: (on Windows)

 f = open('c:/foo.txt', 'r')
 f.read()
'this line contains as\nbut this has as\n'
 f = open('c:/foo.txt', 'rb')
 f.read()
'this line contains as\r\nbut this has as\r\n'

[snip]

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

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


[Tutor] OT looking for help creating a thumbnail

2008-07-22 Thread johnf
Hi,
I'm sorry this is OT but you guys are very knowledgeable with the world of 
python.  I already tried the python list. - no response.

I need a py tool that will provide a thumbnail (bmp?) from a video (avi,
wmv) that will be cross platform (linux, windows).  Research has provided
pymedia for Linux but I haven't found anything for windows.  Hopefully,
someone has had to do this in the past and knows what has to be done.

Thanks in Advance,
Johnf

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


Re: [Tutor] checking if data files are good, readable, and exist

2008-07-22 Thread Alan Gauld
bob gailer [EMAIL PROTECTED] wrote 


But that isn't. Python just reads the data and interprets it
as text if you specify a text file - the default - or as raw data
if you use rb.


But it DOES handle line-ends in an OS independent manner. 


OK, I'll grant you that small piece of data manipulation. :-)

(Although it could be argued that even that is just translating 
two bytes into one character in the set.)


Alan G.


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


Re: [Tutor] question about socket status

2008-07-22 Thread arsyed
On Mon, Jul 21, 2008 at 1:25 PM, Rupp, Romaine [EMAIL PROTECTED] wrote:
 Hello,

 I am new to programming with python and sockets.

 I would like to determine the status of a socket as it  is returned when you
 do 'netstat –a | grep port#'.  I would like  to know if the socket state
 is ESTABLISHED, LISTEN , CLOSE_WAIT, etc.

 Is there a way to get this information through a socket call?

 I've tried using socket.getperrname() function, but that only tells if there
 is a connection.

 Is there a way to get more information on the state of the socket
 connection?



If you're on linux, you could try poking around /proc/net. See, for example:

http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html

But I think invoking netstat and parsing the output from python might
work well enough.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Online class/education for Python?

2008-07-22 Thread Danyelle Gragsone
 http://mail.python.org/mailman/listinfo/tutor

 Hi,

 I have the Second Edition of PPftAB, and it was published in 2006.
 The version of Python used in PPftAB2E is Python 2.3.5.
 I'm running Python 2.4.4 on Debian GNU/Linux. So far, no problems.

 The only problems I can see you having is if the examples in your book
 use a feature that is no longer used in Python. Otherwise, I don't think
 you'll have any problems. The core principles of Python Programming
 remain the same.

 Just out of curiosity, when was the First Edition published? Which version
 of Python is used in the book?


It was done in 2003.  The version of python the book uses is 2.2.3.
However, it does talk about using the latest versions of python.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor