[Tutor] Structured files?

2011-06-02 Thread Válas Péter
Good morning, I can create files and write strings/unicodes. Is it possible to write a list, a dictionary or an object or anything into a file? Or do I have to transform them to strings? Péter ___ Tutor maillist - Tutor@python.org To unsubscribe or ch

Re: [Tutor] Structured files?

2011-06-02 Thread Simon Yan
2011/6/2 Válas Péter : > Good morning, > > I can create files and write strings/unicodes. > Is it possible to write a list, a dictionary or an object or anything into a > file? Or do I have to transform them to strings? Yes you can. I guess the question is how you want the information to be structu

Re: [Tutor] Structured files?

2011-06-02 Thread Válas Péter
2011. június 2. 9:29 Simon Yan írta, : > Yes you can. > I guess the question is how you want the information to be structured. > IMHO, everything in Python can be "string-lized". > > What is the syntax then? I have Windows XP. The code is: f=open("xxx.dat","w") f.write("fff") d={'one':1, 2:'two'}

Re: [Tutor] Structured files?

2011-06-02 Thread Simon Yan
2011/6/2 Válas Péter : > > > 2011. június 2. 9:29 Simon Yan írta, : >> >> Yes you can. >> I guess the question is how you want the information to be structured. >> IMHO, everything in Python can be "string-lized". >> > What is the syntax then?  I have Windows XP. The code is: > f=open("xxx.dat","w"

Re: [Tutor] Structured files?

2011-06-02 Thread Walter Prins
>Is it possible to write a list, a dictionary or an object or anything into a file? Or do I have to transform them to strings? Have a look at the pickle module: http://docs.python.org/library/pickle.html ___ Tutor maillist - Tutor@python.org To unsubsc

Re: [Tutor] Structured files?

2011-06-02 Thread Alan Gauld
"Válas Péter" wrote I can create files and write strings/unicodes. Is it possible to write a list, a dictionary or an object or anything into a file? Or do I have to transform them to strings? You can write anything to a file, but the file will need to be opened in binary mode(see the docs).

Re: [Tutor] Structured files?

2011-06-02 Thread Alan Gauld
"Válas Péter" wrote Modified code: f=open("xxx.dat","wb") The others remain as above, just I wrote wb. Yes, you need to use binary mode. I read something about a pack function, is that the key? See the file handling topic in my tutorial for a simple example of using the struct module(whic

Re: [Tutor] Structured files?

2011-06-02 Thread Válas Péter
2011. június 2. 10:52 Simon Yan írta, : > Try this: > f.write(str(d)) > > That's what I first asked, this is not a structured file then, this is a structure transformed to a string. Thanks for the idea of pickle, I will look at it. ___ Tutor maillist -

Re: [Tutor] Structured files?

2011-06-02 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Válas Péter wrote: 2011. június 2. 9:29 Simon Yan írta,: Yes you can. I guess the question is how you want the information to be structured. IMHO, everything in Python can be "string-lized". What is the syntax then? I have Windows XP. The code is: f=open("xxx.dat",

Re: [Tutor] Python Extensions in C

2011-06-02 Thread James Reynolds
I fixed it. I find if I sleep on things I have a better chance at fixing them. Maybe I will get some real work done today instead of going all OCD on this side project? Here's the dif: http://pastebin.com/KYBab3H9 I'll address your points in a second, but here's how I found the problem (Python is

Re: [Tutor] checking if a variable is an integer?

2011-06-02 Thread Prasad, Ramit
>If not, he can google the bits he doesn't understand, or ask. We won't bite! Unless he asks for it ;) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This communication is for informational purpo

[Tutor] Introduction

2011-06-02 Thread Jamie Griffin
Hello everyone I'm not sure if introductions are customary on this list but I thought I would anyway as I'm going to be using it quite a bit from now. I am just starting out with python and I will no doubt get stuck and need some assistance from you all soon. I'll try my best to keep the stupidit

Re: [Tutor] Introduction

2011-06-02 Thread David Abbott
On Thu, Jun 2, 2011 at 10:12 AM, Jamie Griffin wrote: > Hello everyone > > I'm not sure if introductions are customary on this list but I thought > I would anyway as I'm going to be using it quite a bit from now. > > I am just starting out with python and I will no doubt get stuck and > need some

Re: [Tutor] Structured files?

2011-06-02 Thread Alexandre Conrad
2011/6/2 Válas Péter : > I can create files and write strings/unicodes. > Is it possible to write a list, a dictionary or an object or anything into a > file? Or do I have to transform them to strings? As suggested by Walter, you should use the Pickle module to serialize your Python objects so the

Re: [Tutor] Structured files?

2011-06-02 Thread Alan Gauld
"Alexandre Conrad" wrote you want to share that data between non-Python application, I could also suggest the use of the JSON module. JSON is a standard format (see json.org) supported by many programming languages. But isn't it a string based format? I thought JSON converted everything int

Re: [Tutor] Structured files?

2011-06-02 Thread Walter Prins
On 2 June 2011 17:13, Alan Gauld wrote: > But isn't it a string based format? > I thought JSON converted everything into XML strings? > > It's text based yes, although not XML. As for efficiency, I'd be of the view that it's probably efficient enough for the vast majority of use cases, especiall

Re: [Tutor] Structured files?

2011-06-02 Thread Steven D'Aprano
Alan Gauld wrote: "Alexandre Conrad" wrote you want to share that data between non-Python application, I could also suggest the use of the JSON module. JSON is a standard format (see json.org) supported by many programming languages. But isn't it a string based format? I thought JSON conve

Re: [Tutor] Structured files?

2011-06-02 Thread Prasad, Ramit
>But I've only used JSON once from within TurboGears so >I am no expert! If you use Firefox you have used JSON ;) that is how it stores bookmarks. I am sure it is more widely used than that. Usage seems to be on the rise but that could be that I see it more now that I know what it is. Ramit

Re: [Tutor] __init__.py question

2011-06-02 Thread Marilyn Davis
Thank you for your careful explanation, Steven. I guess there's nothing more for me to know. While I think it is a mistake to put directories in your package directory structure that aren't part of the package, that seems to be all it's about. Well, I guess I don't feel quite so stupid. Thank y

Re: [Tutor] checking if a variable is an integer?

2011-06-02 Thread Marilyn Davis
True that! This is the nicest, most patient, most knowledgeable, technical list I've ever experienced. That's why I keep coming back when I am hopelessly confused. Thank you. Marilyn Davis On Thu, June 2, 2011 7:04 am, Prasad, Ramit wrote: >> If not, he can google the bits he doesn't underst

Re: [Tutor] Strategy to read a redirecting html page

2011-06-02 Thread Robert Sjoblom
> When you hit the page and you get an HTTP redirect code back (say, > 302), you will need to make another call to the URL specified in the > "Location" parameter in the response headers. Then you retrieve that > new page and you can check you got an acceptable HTTP response code > (such as 200) an

Re: [Tutor] Strategy to read a redirecting html page

2011-06-02 Thread Brett Ritter
On Thu, Jun 2, 2011 at 4:06 PM, Robert Sjoblom wrote: > Python already has the urllib/urllib2 package that automatically > follow redirects, so I don't see why you'd need a 3rd-party module to > deal with it? When it encounters a 301 status code from the server, Ah, but I believe the issue is tha

Re: [Tutor] Strategy to read a redirecting html page

2011-06-02 Thread Robert Sjoblom
On 2 June 2011 22:50, Brett Ritter wrote: > On Thu, Jun 2, 2011 at 4:06 PM, Robert Sjoblom > wrote: >> Python already has the urllib/urllib2 package that automatically >> follow redirects, so I don't see why you'd need a 3rd-party module to >> deal with it? When it encounters a 301 status code f

Re: [Tutor] Structured files?

2011-06-02 Thread Alan Gauld
"Prasad, Ramit" wrote >But I've only used JSON once from within TurboGears so If you use Firefox you have used JSON ;) Yeah, OK, I've used JSON on loads of apps in that sense. I meant I've only programmed with JSON once... But I suspect you knew that! :-) -- Alan Gauld Author of the L

Re: [Tutor] Structured files?

2011-06-02 Thread Alan Gauld
"Steven D'Aprano" wrote That makes it hugely wasteful of space which is usually the reason for using a binary format in the first place. Meh, who cares whether your 100K of data takes 300K on disk? :) It depends on your volumes and your platform. About 10 years ago I bought 10G of storage f