Re: Not clear about the dot notation
On Jan 16, 3:24 pm, TomF wrote: > vote refers to the Vote instance. So he must have instatiated previously like vote = Vote() is this correct? So I have a model class Item(db.Model): title = db.StringProperty() url = db.StringProperty() date = db.DateTimeProperty(auto_now_add=True) author = db.UserProperty() and to write to the database I do item = Item() item.title = self.request.get("title") item.url = self.request.get("url") item.author = users.get_current_user() item.put() self.redirect("/newest") so his vote.vote is like my item.url ? -- http://mail.python.org/mailman/listinfo/python-list
Not clear about the dot notation
What does vote.vote refer to in this snippet? def txn(): quote = Quote.get_by_id(quote_id) vote = Vote.get_by_key_name(key_names = user.email(), parent = quote) if vote is None: vote = Vote(key_name = user.email(), parent = quote) if vote.vote == newvote: return quote.votesum = quote.votesum - vote.vote + newvote vote.vote = newvote from here: http://code.google.com/appengine/articles/overheard.html -- http://mail.python.org/mailman/listinfo/python-list
How do I get the email address of the person who clicked the link in the email?
Hello, I am working with Google App Engine python version. The app sends an email to the user with a link to a page to upload an image as an avatar. It would be nice to have the email so that I can associate the avatar with that email. How can I do this? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Why datetime module is so complicated?
It's about a week now I've been trying to convert a datetime object to seconds since epoch; the object is set to current time by class Rep() in Google App Engine: class Rep(db.Model): ... mCOUNT = db.IntegerProperty() mDATE0 = db.DateTimeProperty(auto_now_add=True) mWEIGHT = db.FloatProperty() I want to divide mDATE0 by the integer mCOUNT. I asked the same question here previously and also at stackoverflow. So far, I still cannot make it work. I would greatly appreciate if someone who is an expert in datetime operation in Python could help me understand this issue. Thank you. Latest question in Stackoverlow with link to my original question there: http://stackoverflow.com/questions/4178125/datetime-and-utctimetuple Previous discussions at comp.lang.python: http://groups.google.com/group/comp.lang.python/browse_frm/thread/ac9a2c89bed67869/28c7c7b8d48f3805?hl=en#28c7c7b8d48f3805 http://groups.google.com/group/comp.lang.python/browse_frm/thread/a5aeb6c40ae08450/fd9b42e0c403380e?hl=en#fd9b42e0c403380e -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to break a string literal into multiple lines?
Tim Chase and MRAB: Thanks!! On Nov 13, 2:14 pm, Tim Chase wrote: > On 11/13/2010 12:53 PM, Zeynel wrote: > > > > > > > > > > > I have string formatting line in Google App Engine webframe webapp: > > > self.response.out.write("%s: mWEIGHT: %s > > mDATE0_integer: %s mCOUNT: %s" % (result.mUNIQUE, > > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > > I would like to be able to write it as > > > self.response.out.write("%s: > > mWEIGHT: %s > > mDATE0_integer: %s > > mCOUNT: %s" > > % > > (result.mUNIQUE, > > > result.mWEIGHT, > > > mDATE0_integer, > > > result.mCOUNT,)) > > > But neither \ or enclosing the string in parens let me break the > > string literal enclosed in "" Is this possible? > > Use python's triple-quoted strings: > > self.response.out.write("""%s: > mWEIGHT: %s ... > ... """) > > Or alternatively, you can do something like > > self.response.out.write( > "%s:br />" > "mWEIGHT: %s ..." > ... > "..." > ) > > (that excludes newlines and leading whitespace in the string that > gets written, but you can modify the string contents to include > them if you need/want) > > -tkc -- http://mail.python.org/mailman/listinfo/python-list
Is it possible to break a string literal into multiple lines?
I have string formatting line in Google App Engine webframe webapp: self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s " % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) I would like to be able to write it as self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s " % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) But neither \ or enclosing the string in parens let me break the string literal enclosed in "" Is this possible? -- http://mail.python.org/mailman/listinfo/python-list
How to read the Python tutorial?
For instance, when the tutorial has http://docs.python.org/release/2.6/library/datetime.html class datetime.datetime A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo. What does this mean? How do I use it? For instance, I have a DateTimeProperty mDate that I get from a query in Google App Engine. This mDate has value mDATE = 2010-11-10 14:35:22.863000 But when I try datetime.datetime.mDATE.toordinal()) I get AttributeError. If I try something like td = mDATE.seconds in GAE development server I get AttributeError: 'datetime.datetime' object has no attribute 'seconds' What am I doing wrong? And how to understand this stuff so that I can start using the language instead of trying to figure out types. Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to read the Python tutorial?
On Nov 10, 10:51 am, rantingrick wrote: > Wait a minute i am confused...? Does Python have a "text" object that > magically turns into a datetime object? > > >>> mDATE = 2010-11-10 14:35:22.863000 > > SyntaxError: invalid syntax This is the reason I am asking the question. I am confused about what mDATE is. It is defined as a DateTimeProperty in Google App Engine in the following model: class Rep(db.Model): mAUTHOR = db.UserProperty(auto_current_user=True) mUNIQUE = db.StringProperty() mCOUNT = db.IntegerProperty() mDATE = db.DateTimeProperty(auto_now=True) mDATE0 = db.DateTimeProperty(auto_now_add=True) mWEIGHT = db.IntegerProperty() When I acces it with this query: QUERY = Rep.all() QUERY.filter("mAUTHOR =", user) QUERY.order("-mCOUNT") RESULTS = QUERY.fetch(10) But when I try to use like this for instance: for result in RESULTS: WEIGHT = (datetime.datetime.result.mDATE.toordinal()) * result.mCOUNT I get AttributeError or if I try to use it like this dt = result.mDATE.seconds I get AttributeError: 'datetime.datetime' object has no attribute 'seconds' -- http://mail.python.org/mailman/listinfo/python-list
How to convert the date object 2010-11-10 14:52:35.026000 to integer?
mDATE = "2010-11-10 14:52:35.026000" (Not sure if this is string or something else.) I would like to convert mDATE to integer to add, multiply etc. For instance, if I try to convert mDATE to seconds td = mDATE.seconds I get the error td = result.mDATE.seconds AttributeError: 'datetime.datetime' object has no attribute 'seconds' Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to pring a list object in Python?
On Oct 31, 2:44 pm, Benjamin Kaplan wrote: > Rep() = Rep object > Rep.all() = Query object > list(Rep.all()) = List of Rep objects. > list(Rep.all())[0] = A single Rep object > list(Rep.all())[0].replist = A list > Thanks! This was very helpful. -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception handling with NameError
On Nov 5, 1:26 pm, Peter Otten <__pete...@web.de> wrote: > Of course I'm only guessing because you don't provide enough context. > > Peter Thanks. This is the problem I am having, in general: K = [] # a container list K = ["A", "B"] ARCHIVE = [] # a list where items from K is archived ARCHIVE.append(K) # K is updated K = ["C", "D"] # append new K to ARCHIVE ARCHIVE.append(K) The problem I am having is this: If I do: K = [] ARCHIVE = [] ARCHIVE.append(K) any time K is updated (user submits new input) the content of ARCHIVE is erased: If I do this: K = [] ARCHIVE.append(K) I get NameError: "Name ARCHIVE not defined" What is the solution? -- http://mail.python.org/mailman/listinfo/python-list
Exception handling with NameError
Hello, I want to append new input to list SESSION_U without erasing its content. I try this: ... try: SESSION_U.append(UNIQUES) except NameError: SESSION_U = [] SESSION_U.append(UNIQUES) ... I would think that at first try I would get the NameError and SESSION_U list would be created and appended; the second time try would work. But it does not. Do you know why? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to pring a list object in Python?
On Oct 31, 5:52 am, Dave Angel wrote: > On 2:59 PM, Zeynel wrote:> class Rep(db.Model): > > author = db.UserProperty() > > replist = db.ListProperty(str) > > unique = db.ListProperty(str) > > date = db.DateTimeProperty(auto_now_add=True) > > > > > > Rep().replist = L > > Rep().put() > > mylist = Rep().all().fetch(10) > > > I am trying to display mylist; but I am getting the object. Thanks. > > I don't know any meaning for "pring." > > Care to mention what db is? Presumably it's some other module, not in > the standard library, that you've imported. And presumably it has a > class called Model defined in it. > > But the three lines following make no sense to me in isolation, so > unless you know how db.Model is intended to be used, I can't imagine > what you expect here. Rep().replist = L creates a temporary object, > gives it an attribute, and throws them both away. Although I could > write code that would have enough side effects to do something with > that, I can't imagine why I would want to. > > Be more explicit with the assumptions (in this case, at least show the > import), and with the results. So instead of saying "I am getting the > object," say > > print mylist > > produces the output: > > sjfdsljdsfds;lkjfdsfds > fdsljfds;ldsj;dslkjfds > dsfjlfkjslkjfd s fj lkjfd > > DaveA I am using Google App Engine, but it seems that the problem is a Python problem. I fixed the code a little bit, now I can print the lists: Rep().replist = L Rep().put() query = Rep.all() for result in query: self.response.out.write(result.replist) The output of this is: [u'a', u'b'][u'a', u'b'][u'a', u'b']. . . So, these are the lists in datastore. I want to take one of these lists and apply list method on it. How do I do that? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to pring a list object in Python?
On Oct 31, 3:00 am, Richard Thomas wrote: > On Oct 31, 5:42 am, Zeynel wrote: > > > class Rep(db.Model): > > author = db.UserProperty() > > replist = db.ListProperty(str) > > unique = db.ListProperty(str) > > date = db.DateTimeProperty(auto_now_add=True) > > > > > > Rep().replist = L > > Rep().put() > > mylist = Rep().all().fetch(10) > > > I am trying to display mylist; but I am getting the object. Thanks. > > You're using GAE? I suspect the return value of Query.fetch is an > iterator and not a list. You can make it a list by passing it to the > list constructor, like so: > > mylist = list(Rep.all().fetch(10)) > > Richard. Yes. I am using GAE, thanks. I tried mylist = list(Rep().all().fetch(10)) and tried to render it with Mako template % for i in mylist: ${i} % endfor I still get the output: len(mylist): 2 <__main__.Rep object at 0x03AE6C50> <__main__.Rep object at 0x03AE6270> As far as I understand there are two items in mylist and they are Rep objects. But previously I wrote the list L to datastore: L = [] s = self.request.get('sentence') L.append(s) L = L[0].split('\r\n') Rep().replist = L Rep().put() mylist = list(Rep().all().fetch(10)) so I don't understand why I fetch a list and I get an object. Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
Is there a way to pring a list object in Python?
class Rep(db.Model): author = db.UserProperty() replist = db.ListProperty(str) unique = db.ListProperty(str) date = db.DateTimeProperty(auto_now_add=True) Rep().replist = L Rep().put() mylist = Rep().all().fetch(10) I am trying to display mylist; but I am getting the object. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using nested lists and tables
On Oct 28, 9:35 am, Iain King wrote: > It's equivalent to: > > if columns: > if columns[-1][0] == s: > dostuff() > > i.e. check columns is not empty and then check if the last item > startswith 's'. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Using nested lists and tables
On Oct 28, 2:32 am, robert wrote: > the reason may be that your text doesn't contain a question (mark). ... > perhaps drill down to a question on python-level. Thanks, I realize that what I was trying to ask is not too clear. I am learning to GAE using Python and I want to deploy a simple app. The app will have a form. The user enters a sentence to the form and presses enter. The sentence is displayed. The user types in the same sentence; the sentence is displayed on the same column; the user types in a different sentence; the different sentence is displayed on the next column; as long as the user types in the same sentence; the sentence is displayed on the same column; otherwise it is displayed on the next column. Maybe nested lists are not the right tool for this. Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: Using nested lists and tables
On Oct 28, 4:49 am, Peter Otten <__pete...@web.de> wrote: Thank you this is great; but I don't know how to modify this code so that when the user types the string 's' on the form in the app he sees what he is typing. So, this will be in GAE. But I have a couple of other questions, for learning purposes. Thanks again, for the help. > ... if columns and columns[-1][0] == s: Here, how do you compare "columns" (a list?) and columns[-1][0] (an item in a list)? >>> for row in range(max(len(c) for c in columns)): > ... print " | ".join(c[row] if len(c) > row else " "*len(c[0]) for c in > columns) What is "c" here? -- http://mail.python.org/mailman/listinfo/python-list
Using nested lists and tables
I am trying to make this simple app for GAE. I get a string s that user enters in a form. I append that to an empty list L = [] then I test if the last saved string is the same as the new string. If same, I write it on the same column; if not the cursor moves to next column (I was trying to do this with tables) and as long as the user types the same string the cursor stays on the same column. If a new string is typed; a new column is started; and so on. I asked the same question at Stackoverflow and HN with no good answers so far. Maybe you can help. Thanks. http://news.ycombinator.com/item?id=1840335 http://news.ycombinator.com/item?id=1841536 http://stackoverflow.com/questions/4011728/conditional-statements-with-python-lists -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question about scrapy tutorial
Now I use EditpadPro and IDLE which appears to be adequate for beginning level. But PyDev looks fun, I'll try it. By the way, I realized that the spider sends the scraped data to the pipelines.py. Now everything is working. On Nov 21, 11:21 am, DreiJane wrote: > Sorry, > > i have no idea what scrapy is - but i see, that you try to use > idle with pipes or anything like that. That cannot work. > idle doesn't even handle __file__ correctly. Use a full-fledged > python IDE (PyDev under Eclipse leaves very few wishes open) or > test in a python interpreter shell. > > Good luck, DreiJane -- http://mail.python.org/mailman/listinfo/python-list
Newbie question about scrapy tutorial
Hello, I have a question about scrapy tutorial and I put 2 questions in the scrapy group http://groups.google.com/group/scrapy-users/t/d5afae7d88672e02 http://groups.google.com/group/scrapy-users/t/4d52fa8c589a412a but there were no answers. Can anyone here help me? The spider works fine but I couldn't figure out where the items file is so that I can print it to a file to transfer it to my database. The same question in stackoverflow http://stackoverflow.com/questions/1771151/newbie-q-about-scrapy-pipeline-py Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: DeprecationWarning on md5
Thanks. I tried the suppress it but no success. I need to read the documentation more carefully. But since this is not error, I will ignore them for now. On Nov 18, 9:12 pm, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 5:23 PM, Zeynel wrote: > > Hello, > > > I am a newbie both in Scrapy and Python. When I create a project with > > Scrapy I get these errors: > > > C:\Python26\lib\site-packages\twisted\python\filepath.py:12: > > DeprecationWarning: the sha module is deprecated; use the hashlib > > module instead import sha > > C:\Python26\lib\site-packages\twisted\spread\pb.py:30: > > DeprecationWarning: the md5 module is deprecated; use hashlib instead > > import md5 > > C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: > > DeprecationWarning: the MimeWriter module is deprecated; use the email > > package instead > > > I found several references to this "bug" but I could not understand > > how to fix it. Can anyone help? > > This is a "bug" in the version of Twisted you're using. What Python is > saying is that Twisted is using some modules from the Python stdlib > that are deprecated and will be removed in some future version of > Python, thus Twisted will /eventually/ need to be changed to use the > newer replacement library. > However, this is only a warning, not an error; the code will run just > fine until you update to the eventual Python version that removed said > deprecated libraries (by which time a new Twisted version will > probably be available with the necessary fixes made). > > So, basically you can safely ignore the warnings, unless you want to > custom-patch your Twisted installation, which I wouldn't particularly > recommend. > It's also entirely possible your Twisted is outdated and a new version > fixed to avoid using the deprecated modules is already available. > > If you want to suppress the output of the warnings, see the docs for > the `warnings` module:http://docs.python.org/library/warnings.html > > Cheers, > Chris > --http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautifulsoup code that is not running
Yes, it shows as empty string. But I learned about Scrapy and now I am studying the tutorial. I like it better than BeautifulSoup. For beginners it is better, I think. On Nov 18, 11:50 am, Peter Pearson wrote: > On Tue, 17 Nov 2009 14:38:55 -0800 (PST), Zeynel wrote: > > [snip] > > >>>> from BeautifulSoup import BeautifulSoup > > >>>> soup = BeautifulSoup (file("test.html").read()) > >>>> title = soup.find('title') > >>>> titleString = title.string > >>>> open('extract.text', 'w').write(titleString) > > > This runs without an error, but nothing is written into the > > extract.text file. test.html has tags in it. > > Hmm. Works for me, but of course I don't have your test.html. > Why don't you try examining "title" and "titleString"? Perhaps > has resulted in titleString being the empty string. > > -- > To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
DeprecationWarning on md5
Hello, I am a newbie both in Scrapy and Python. When I create a project with Scrapy I get these errors: C:\Python26\lib\site-packages\twisted\python\filepath.py:12: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha C:\Python26\lib\site-packages\twisted\spread\pb.py:30: DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5 C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: DeprecationWarning: the MimeWriter module is deprecated; use the email package instead I found several references to this "bug" but I could not understand how to fix it. Can anyone help? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Beautifulsoup code that is not running
Hello, Please help with this code suggested in the beautifulsoup group http://groups.google.com/group/beautifulsoup/browse_frm/thread/d288555c6992ceaa >>> from BeautifulSoup import BeautifulSoup >>> soup = BeautifulSoup (file("test.html").read()) >>> title = soup.find('title') >>> titleString = title.string >>> open('extract.text', 'w').write(titleString) This runs without an error, but nothing is written into the extract.text file. test.html has tags in it. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with read() write()
On Oct 31, 3:11 pm, Terry Reedy wrote: Great, thanks. > Zeynel wrote: > > On Oct 31, 10:40 am, "Alf P. Steinbach" wrote: > > Thanks! This works. But I need to close the file before read and open > > it again with "r", otherwise I get the garbage again. Can you give me > > the link where you got this in documentation: > > > "The mode 'w+' opens and truncates the file to 0 bytes, while 'r+' > > opens the > >> file without truncation." > > > Only place i could find it was in this bug > > report:http://bugs.python.org/issue5061 > > LibRef / builtin functions /open > The entry is a full page. > > Get familiar with this section and the Built-in Types section. > > Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with read() write()
On Oct 31, 10:40 am, "Alf P. Steinbach" wrote: Thanks! This works. But I need to close the file before read and open it again with "r", otherwise I get the garbage again. Can you give me the link where you got this in documentation: "The mode 'w+' opens and truncates the file to 0 bytes, while 'r+' opens the > file without truncation." Only place i could find it was in this bug report: http://bugs.python.org/issue5061 > * Zeynel: > > > > > > > On Oct 31, 9:55 am, "Alf P. Steinbach" wrote: > >> * Zeynel: > > >>> On Oct 31, 9:23 am, "Alf P. Steinbach" wrote: > >>>> * Zeynel: > >>>>> Hello, > >>>>> I've been studying the official tutorial, so far it's been fun, but > >>>>> today I ran into a problem with the write(). So, I open the file pw > >>>>> and write "hello" and read: > >>>>> f = open("pw", "r+") > >>>>> f.write("hello") > >>>>> f.read() > >>>>> But read() returns a bunch of what looks like meta code: > >>>>> "ont': 1, 'center_insert_even\xc4\x00K\x02\xe8\xe1[\x02z\x8e > >>>>> \xa5\x02\x0b > >>>>> \x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > >>>>> 0'QUEUE'\np1\n > >>>>> (S'exec' > >>>>> What am I doing wrong? Thank you. > >>>> After the 'write' the current position in the file is after the "hello", > >>>> so > >>>> reading will read further content from there. > >>>> The following works (disclaimer: I'm utter newbie in Python, and didn't > >>>> consult > >>>> the documentation, and it's the first time I've seen the Python 'open'): > >>>> f = open("pw", "r+") > >>>> f.write( "hello" ) > >>>> f.seek( 0 ) # Go back to start of file > >>>> f.read() > >>>> f.close() > >>>> Cheers & hth., > >>>> - Alf > >>> Thanks, but it didn't work for me. I still get the meta file. Although > >>> I see that "hello" is there. > >> Just a thought: try "w+" instead of "r+". > > >> Because if you do > > >> print( open.__doc__ ) > > >> as I recall it said something about "w" truncating the file? > > >> Cheers & hth., > > >> - Alf > > > No :) I still got the same thing. > > Hm. Now I had to look in the docs because I thought I'd given bad advice. > > Doc of 'open' says: > > "The mode 'w+' opens and truncates the file to 0 bytes, while 'r+' opens > the > file without truncation." > > So with 'w+' the only way to get garbage is if 'read' reads beyond the end of > file, or 'open' doesn't conform to the documentation. > > Testing with Python 3.1.1 under Windows XP Pro: > > > >>> f = open( "zilly", "w+" ) > >>> f.write( > "garbagegarbagegarbagegarbagegarbagegarbagegarbagegarbagegarbage" ) > 63 > >>> f.close() > >>> f = open( "zilly", "r" ) > >>> f.read() > 'garbagegarbagegarbagegarbagegarbagegarbagegarbagegarbagegarbage' > >>> f.close() > >>> f.open( "zilly", "r+" ) > Traceback (most recent call last): > File "", line 1, in > AttributeError: '_io.TextIOWrapper' object has no attribute 'open' > >>> open( "zilly", "r+" ) > <_io.TextIOWrapper name='zilly' encoding='cp1252'> > >>> f = open( "zilly", "r+" ) > >>> f.write( "hello" ) > 5 > >>> f.seek( 0 ) > 0 > >>> f.read() > 'hellogegarbagegarbagegarbagegarbagegarbagegarbagegarbagegarbage' > >>> f.close() > >>> f = open( "zilly", "w+" ) > >>> f.write( "hello" ) > 5 > >>> f.seek( 0 ) > 0 > >>> f.read() > 'hello' > >>> f.close() > >>> > > > The "w+" works here. Even if I made a typing mistake and apparently left the > file open in the middle there. > > Cheers & hth., > > - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with read() write()
On Oct 31, 9:55 am, "Alf P. Steinbach" wrote: > * Zeynel: > > > > > > > On Oct 31, 9:23 am, "Alf P. Steinbach" wrote: > >> * Zeynel: > > >>> Hello, > >>> I've been studying the official tutorial, so far it's been fun, but > >>> today I ran into a problem with the write(). So, I open the file pw > >>> and write "hello" and read: > >>> f = open("pw", "r+") > >>> f.write("hello") > >>> f.read() > >>> But read() returns a bunch of what looks like meta code: > >>> "ont': 1, 'center_insert_even\xc4\x00K\x02\xe8\xe1[\x02z\x8e > >>> \xa5\x02\x0b > >>> \x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > >>> 0'QUEUE'\np1\n > >>> (S'exec' > >>> What am I doing wrong? Thank you. > >> After the 'write' the current position in the file is after the "hello", so > >> reading will read further content from there. > > >> The following works (disclaimer: I'm utter newbie in Python, and didn't > >> consult > >> the documentation, and it's the first time I've seen the Python 'open'): > > >> f = open("pw", "r+") > >> f.write( "hello" ) > >> f.seek( 0 ) # Go back to start of file > >> f.read() > >> f.close() > > >> Cheers & hth., > > >> - Alf > > > Thanks, but it didn't work for me. I still get the meta file. Although > > I see that "hello" is there. > > Just a thought: try "w+" instead of "r+". > > Because if you do > > print( open.__doc__ ) > > as I recall it said something about "w" truncating the file? > > Cheers & hth., > > - Alf No :) I still got the same thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with read() write()
On Oct 31, 9:23 am, "Alf P. Steinbach" wrote: > * Zeynel: > > > > > > > Hello, > > > I've been studying the official tutorial, so far it's been fun, but > > today I ran into a problem with the write(). So, I open the file pw > > and write "hello" and read: > > > f = open("pw", "r+") > > f.write("hello") > > f.read() > > > But read() returns a bunch of what looks like meta code: > > > "ont': 1, 'center_insert_even\xc4\x00K\x02\xe8\xe1[\x02z\x8e > > \xa5\x02\x0b > > \x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > > 0'QUEUE'\np1\n > > (S'exec' > > > What am I doing wrong? Thank you. > > After the 'write' the current position in the file is after the "hello", so > reading will read further content from there. > > The following works (disclaimer: I'm utter newbie in Python, and didn't > consult > the documentation, and it's the first time I've seen the Python 'open'): > > f = open("pw", "r+") > f.write( "hello" ) > f.seek( 0 ) # Go back to start of file > f.read() > f.close() > > Cheers & hth., > > - Alf Thanks, but it didn't work for me. I still get the meta file. Although I see that "hello" is there. -- http://mail.python.org/mailman/listinfo/python-list
problem with read() write()
Hello, I've been studying the official tutorial, so far it's been fun, but today I ran into a problem with the write(). So, I open the file pw and write "hello" and read: f = open("pw", "r+") f.write("hello") f.read() But read() returns a bunch of what looks like meta code: "ont': 1, 'center_insert_even\xc4\x00K\x02\xe8\xe1[\x02z\x8e \xa5\x02\x0b \x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'QUEUE'\np1\n (S'exec' What am I doing wrong? Thank you. -- http://mail.python.org/mailman/listinfo/python-list