Re: text file reformatting

2010-10-31 Thread iwawi
On 31 loka, 21:48, Tim Chase  wrote:
> > PRJ01001 4 00100END
> > PRJ01002 3 00110END
>
> > I would like to pick only some columns to a new file and put them to a
> > certain places (to match previous data) - definition file (def.csv)
> > could be something like this:
>
> > VARIABLE   FIELDSTARTS     FIELD SIZE      NEW PLACE IN NEW DATA FILE
> > ProjID     ;       1       ;       5       ;       1
> > CaseID     ;       6       ;       3       ;       10
> > UselessV  ;        10      ;       1       ;
> > Zipcode    ;       12      ;       5       ;       15
>
> > So the new datafile should look like this:
>
> > PRJ01    001       00100END
> > PRJ01    002       00110END
>
> How flexible is the def.csv format?  The difficulty I see with
> your def.csv format is that it leaves undefined gaps (presumably
> to be filled in with spaces) and that you also have a blank "new
> place in new file" value.  If instead, you could specify the
> width to which you want to pad it and omit variables you don't
> want in the output, ordering the variables in the same order you
> want them in the output:
>
>   Variable; Start; Size; Width
>   ProjID; 1; 5; 10
>   CaseID; 6; 3; 10
>   Zipcode; 12; 5; 5
>   End; 16; 3; 3
>
> (note that I lazily use the same method to copy the END from the
> source to the destination, rather than coding specially for it)
> you could do something like this (untested)
>
>    import csv
>    f = file('def.csv', 'rb')
>    f.next() # discard the header row
>    r = csv.reader(f, delimiter=';')
>    fields = [
>      (varname, slice(int(start), int(start)+int(size)), width)
>      for varname, start, size, width
>      in r
>      ]
>    f.close()
>    out = file('out.txt', 'w')
>    try:
>      for row in file('data.txt'):
>        for varname, slc, width in fields:
>          out.write(row[slc].ljust(width))
>        out.write('\n')
>    finally:
>      out.close()
>
> Hope that's fairly easy to follow and makes sense.  There might
> be some fence-posting errors (particularly your use of "1" as the
> initial offset, while python uses "0" as the initial offset for
> strings)
>
> If you can't modify the def.csv format, then things are a bit
> more complex and I'd almost be tempted to write a script to try
> and convert your existing def.csv format into something simpler
> to process like what I describe.
>
> -tkc- Piilota siteerattu teksti -
>
> - Näytä siteerattu teksti -

Hi,

Thanks for your reply.

Def.csv could be modified so that every line has the same structure:
variable name, field start, field size and new place and would be
separated with semicolomns as you mentioned.

I tried your script (which seems quite logical) but I get this

Traceback (most recent call last):
  File "testing.py", line 16, in 
out.write (row[slc].ljust(width))
TypeError: an integer is required

Yes - you said it was untested, but I can't figure out how to
proceed...
-- 
http://mail.python.org/mailman/listinfo/python-list


python script to read google spreadsheet

2010-10-31 Thread charu gangal
import gdata.spreadsheet.service
username= 'prakhil.purch...@gmail.com'
passwd  = 'purchase'
doc_name= 'googleapps_spreadsheet'
gd_client = gdata.spreadsheet.service.SpreadsheetsService()
gd_client.email = username
gd_client.password =passwd
#gd_client.source = 'pythonsample12'
gd_client.ProgrammaticLogin()
q = gdata.spreadsheet.service.DocumentQuery()
q['title'] = doc_name
q['title-exact'] = 'true'
feed = gd_client.GetSpreadsheetsFeed(query=q)
spreadsheet_id = feed.entry[0].id.text.rsplit('/',1)[1]
feed = gd_client.GetWorksheetsFeed(spreadsheet_id)
worksheet_id = feed.entry[0].id.text.rsplit('/',1)[1]
rows = gd_client.GetListFeed(spreadsheet_id, worksheet_id).entry
for row in rows:
for key in row.custom:
print " %s: %s" % (key, row.custom[key].text)


This is the python code I was trying to access the cell information
from a google spreadsheet but the issue is that i am able to make it
work on Eclipse but when i deploy it, it is not showing me the result.
Maybe I am missing some of the google packages to import that is
making it unable to run on google environment. Kindly guide me.Thanks
in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Allowing comments after the line continuation backslash

2010-10-31 Thread Yingjie Lan
Hi,

Sorry if I am baking too many ideas today.
I am just having trouble with the backslashes

I would like to have comments after the line continuation backslash.

>>> if a > 0 \ #comments for this condition
  and b > 0:
#do something here

This is currently not OK, but this might be a good thing to have.

Yingjie


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


Re: with block for multiple files

2010-10-31 Thread Yingjie Lan
> Guido's time machine strikes again! It's already in Python
> 3; your
> example would be spelled:
> 
> with open('scores.csv') as f, open('grades.csv', wt) as g:
>     g.write(f.read())
> 

Indeed! Thanks, Chris and James.

Yingjie


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


Allow multiline conditions and the like

2010-10-31 Thread Yingjie Lan
Hi,

This is a mini-proposal I piggy-tailed in the other topic:

Allow the conditions in the if-, elif-, while-, for-, and
with-clauses to span multiple lines without using a backlalsh
at the end of a line, 
just like when you specify literal lists, tuples, dicts, etc.
across multiple lines (similar to comprehensions too).

My reasons:

   because they all must end with a required colon ':',
so nobody will mistake it. 

   also, if we don't allow it, people just have to use
parenthesis around the expressions to make that happen.


Just a half-baked idea, appreciate all comments.

Yingjie


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


Re: with block for multiple files

2010-10-31 Thread James Mills
On Mon, Nov 1, 2010 at 3:03 PM, Yingjie Lan  wrote:
> with open('scores.csv'), open('grades.csv', wt) as f,g:
>     g.write(f.read())

One could write their own ContextManager here...

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: with block for multiple files

2010-10-31 Thread Chris Rebert
On Sun, Oct 31, 2010 at 10:03 PM, Yingjie Lan  wrote:
> Hi,
>
> Suppose I am working with two files simultaneously,
> it might make sense to do this:
>
> with open('scores.csv'), open('grades.csv', wt) as f,g:
>     g.write(f.read())
>
> sure, you can do this with nested with-blocks,
> but the one above does not seem too complicated,
> it is like having a multiple assignment...
>
> Any thoughts?

Guido's time machine strikes again! It's already in Python 3; your
example would be spelled:

with open('scores.csv') as f, open('grades.csv', wt) as g:
g.write(f.read())

Cheers,
Chris
--
Where does GvR source his flux capacitors from?
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


with block for multiple files

2010-10-31 Thread Yingjie Lan
Hi,

Suppose I am working with two files simultaneously, 
it might make sense to do this:

with open('scores.csv'), open('grades.csv', wt) as f,g:
 g.write(f.read())

sure, you can do this with nested with-blocks, 
but the one above does not seem too complicated,
it is like having a multiple assignment...

Any thoughts?

Another mini-proposal: 

Allow the conditions in the if-, elif-, while-, for-, and 
with-clauses to span multiple lines without using a backlalsh, 
just like when you specify literal lists, tuples, dicts, etc.
across multiple lines (similar to comprehensions too).

My reason is this: 
   because they all must end with a required colon ':',
so nobody will mistake it.

Just some half-baked ideas, would appreciate 
thos who shed light on these issues.

Yingjie


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


Re: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate?

2010-10-31 Thread Ben Finney
brad...@hotmail.com writes:

> Sorry, to clarify I heard that when you declare a variable in python
> you have to use some sort of standard boiler plate _variable_ however
> this has not been my experience using IDLE so is this even true?

I don't know what “some sort of boiler plate _variable_” might mean.

Can you point to someone's actual message saying this, so we can see
what they might be talking about?

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate?

2010-10-31 Thread James Mills
On Mon, Nov 1, 2010 at 1:37 PM,   wrote:
> Sorry, to clarify I heard that when you declare a variable in python you have 
> to use some sort of standard boiler plate _variable_ however this has not 
> been my experience using IDLE so is this even true?

Boilerplate, what boilerplate ?

To define variables, just assign a value to a name:

>>> x = 1
>>> x
1

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
> According to msg56377, the behaviour is "optimal" for regular
> expressions. Well, I use regular expressions a lot, and I
> still think it's a nuisance!

Thanks for bringing that up.

Using an otherwise 'dead' backlash to escape quotes 
in raw strings seems like the black magic of 
necromancy to me. :)

To include quotes in a string, there are a couple of
known choices: If you need single quotes in the string, 
start the literal by a double-quote, and vice versa.
In case you need both, you can use a long string:

>>> rab\c"'''

Note that when the last character is also a quote, we can
use the other type of quote three times to delimit the 
long string. Of course, there are still some corner cases:

1. when we need three consecutive single quotes AND three 
   consecutive double quotes in the string.

2. When the last is a single quote, and we also need 
   three consecutive double-quotes in the string, 
   or the other way around.

Then we can abandon the raw string literal, or use 
concatenation of string literals wisely to get it done.

But in total, I still would vote against the nacromancy.

Yingjie


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


Re: I heard about python needing some sort of_VariableName_ boiler plate?

2010-10-31 Thread rantingrick

Brad,

Serously, i have never heard of any boilerplate variables in Python.
Could you show us an example using Python code that compiles? Of could
you even show us some puesdo that resembles any thing that you are
suggesting? I am perplexed! Is this a troll or are you really serious?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I heard about python needing some sort of_VariableName_ boiler plate?

2010-10-31 Thread rantingrick
On Oct 31, 10:37 pm, brad...@hotmail.com wrote:
> Sorry, to clarify I heard that when you declare a variable in python you have 
> to use some sort of standard boiler plate _variable_ however this has not 
> been my experience using IDLE so is this even true?

Halloween night and i am bored... hmm... i know!

plan A: Ask a really perplexing and insane question on c.l.p.

...hmm, well i did not get the answer i wanted so i'll just open a new
thread and...

plan B: Ask ask the same question again!

...surely i'll get a better answer with this plan!!

urm, rinse and repeat maybe?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I heard about python needing some sort of _VariableName_ boiler plate?

2010-10-31 Thread rantingrick
On Oct 31, 10:18 pm, Chris Rebert  wrote:
> On Sun, Oct 31, 2010 at 7:09 PM, Braden Faulkner  wrote:
> > I heard about python needing some sort of _VariableName_ boiler plate?
> > Can anyone explain to me how this works, I don't seem to have to do it in
> > IDLE?

Oh thats just more FUD and spin from the legions of "Perl mongers" and
"Lisp leaches" who continually try to sow discontent within the ranks
of our newbies here at c.l.p. As you have found yourself Python is a
super clean language. However, since they cannot argue the language on
merits and facts they will resort to these despicable (and might i say
desperate) lies and political propagandas in a feeble attempt to sway
the masses against us. However, do not be fearful of their threats or
influenced by such bombastic claims and nonsensical rubbish.

Go and tell Xerxes he faces free men here... not slaves!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A bug for raw string literals in Py3k?

2010-10-31 Thread MRAB

On 01/11/2010 03:30, Yingjie Lan wrote:

All backslashes in raw string literals are

interpreted literally.

(seehttp://docs.python.org/release/3.0.1/whatsnew/3.0.html):


All backslashes in syntactically-correct raw string

literals are interpreted literally.

That's a good way of putting it.



Syntactical correctness obviously depends on the syntax specification.
To cancle the special meaning of ALL backlashes in a raw string literal
makes a lot of sense to me. Currently, the behavior of backslashes
in a raw string literal is rather complicated I think.
In fact, the backlashes can still escape quotes in a raw string,
and one the other hand, it also remains in the string -- I'm
wondering what kind of use case is there to justify such a behavior?
Surely, my experience is way too limited to make a solid judgement,
I Hope others would shed light on this issue.


It has been discussed briefly here: http://bugs.python.org/issue1271

According to msg56377, the behaviour is "optimal" for regular
expressions. Well, I use regular expressions a lot, and I still think
it's a nuisance!
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Beginer Question] I heard about python needing some sort of_VariableName_ boiler plate?

2010-10-31 Thread bradenf
Sorry, to clarify I heard that when you declare a variable in python you have 
to use some sort of standard boiler plate _variable_ however this has not been 
my experience using IDLE so is this even true?

Thanks!

--Original Message--
From: Chris Rebert
Sender: ch...@rebertia.com
To: Braden Faulkner
Cc: Python List
Subject: Re: [Beginer Question] I heard about python needing some sort 
of_VariableName_ boiler plate?
Sent: Oct 31, 2010 11:18 PM

On Sun, Oct 31, 2010 at 7:09 PM, Braden Faulkner  wrote:
> I heard about python needing some sort of _VariableName_ boiler plate?
> Can anyone explain to me how this works, I don't seem to have to do it in
> IDLE?

Your question is extremely vague. Please give more details.

Regards,
Chris



Sent wirelessly from my BlackBerry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
> > > All backslashes in raw string literals are
> interpreted literally.
> > > (seehttp://docs.python.org/release/3.0.1/whatsnew/3.0.html):
> >
> > All backslashes in syntactically-correct raw string
> literals are interpreted literally.
> 
> That's a good way of putting it.
> 

Syntactical correctness obviously depends on the syntax specification.
To cancle the special meaning of ALL backlashes in a raw string literal 
makes a lot of sense to me. Currently, the behavior of backslashes
in a raw string literal is rather complicated I think.
In fact, the backlashes can still escape quotes in a raw string,
and one the other hand, it also remains in the string -- I'm 
wondering what kind of use case is there to justify such a behavior?
Surely, my experience is way too limited to make a solid judgement,
I Hope others would shed light on this issue.

Yingjie


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


Re: [Beginer Question] I heard about python needing some sort of _VariableName_ boiler plate?

2010-10-31 Thread Chris Rebert
On Sun, Oct 31, 2010 at 7:09 PM, Braden Faulkner  wrote:
> I heard about python needing some sort of _VariableName_ boiler plate?
> Can anyone explain to me how this works, I don't seem to have to do it in
> IDLE?

Your question is extremely vague. Please give more details.

Regards,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


[Beginer Question] I heard about python needing some sort of _VariableName_ boiler plate?

2010-10-31 Thread Braden Faulkner

Can anyone explain to me how this works, I don't seem to have to do it in IDLE?
Thanks!   -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-31 Thread cbr...@cbrownsystems.com
On Oct 31, 4:27 pm, Lawrence D'Oliveiro  wrote:
> In message
> <687bcb76-0093-4d68-ba56-0390a3e1e...@30g2000yql.googlegroups.com>,
>
> cbr...@cbrownsystems.com wrote:
> > I should note that efficiency is not an issue to me here; this is for
> > when you have, say, a list user_options of at most around 15 options
> > or so, and you want to perform some action if one or more of a, b, or
> > c is an option listed in user_options. Big O notation isn't so
> > relevant as readability and 'naturalness'.
>
> I must say this whole thread has turned into a massive bikeshedding
> exercise.

Agreed that, to paraphrase RWE, a foolish insistence on big O
valuation is the hobgoblin of etc. On the other hand, I got a
reasonable answer to my question:

if any(option in ['optionA', 'optionB', 'optionC']
for option in supplied_options):
first_do_something_those_options_all_require()
if 'optionA' in supplied_options:
do_optionA_specific_stuff()


which is quite readable and flexible as an idiom, and so I am
satisfied overall.

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


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-31 Thread Lawrence D'Oliveiro
In message
<687bcb76-0093-4d68-ba56-0390a3e1e...@30g2000yql.googlegroups.com>, 
cbr...@cbrownsystems.com wrote:

> I should note that efficiency is not an issue to me here; this is for
> when you have, say, a list user_options of at most around 15 options
> or so, and you want to perform some action if one or more of a, b, or
> c is an option listed in user_options. Big O notation isn't so
> relevant as readability and 'naturalness'.

I must say this whole thread has turned into a massive bikeshedding 
exercise.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-31 Thread Lawrence D'Oliveiro
In message <4cca5aaf$0$1600$742ec...@news.sonic.net>, John Nagle wrote:

> This is cheaper than intersection ...

All together now:

“PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL!”
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Handling in Python 3

2010-10-31 Thread Lawrence D'Oliveiro
In message , Antoine 
Pitrou wrote:

> If you want to present exceptions to users in a different way ...

sys.stderr.write \
  (
"Traceback (most recent call last):\n"
...
"AttributeError: blah blah blah ...\n"
  )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 or 3.1

2010-10-31 Thread Lawrence D'Oliveiro
In message , Jorge 
Biquez wrote:

> Would you consider a "not so intelligent move" for a newsbie to
> Python to have maybe version 2.7 and 3.x (if that's possible to be
> running together on the same machine) to have them run and be
> learning mainly in 2.7 and see differences in 3.x?

Sure, why not become familiar with both if you can handle it. :)

I currently have Python versions 2.5, 2.6 and 3.1 simultaneously installed 
on my Debian system, so that’s no problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compare source code

2010-10-31 Thread Lawrence D'Oliveiro
In message <4ccd5ad9$0$19151$426a7...@news.free.fr>, jf wrote:

> I edit each file to remove tabs ...

expand -i newfile

> Do you know a tools to compare the initial file with the cleaned one to
> know if the algorithms are the same ?

diff -b oldfile newfile

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


Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Ben Finney
John Machin  writes:

> On Oct 31, 11:23 pm, Yingjie Lan  wrote:
> > Thanks! That looks weird to me ... doesn't this contradict with:
> >
> > All backslashes in raw string literals are interpreted literally.
> > (seehttp://docs.python.org/release/3.0.1/whatsnew/3.0.html):
>
> All backslashes in syntactically-correct raw string literals are
> interpreted literally.

That's a good way of putting it.

Yingjie, in case it's not clear: Python can only know what you've
written if it's syntactically correct. The backslash preceding the final
quote means that the code contains bad syntax, not a raw string literal.

Since there's no raw string literal, “backslashes in raw string
literals” doesn't apply.

-- 
 \  “If sharing a thing in no way diminishes it, it is not rightly |
  `\  owned if it is not shared.” —Augustine of Hippo (354–430 CE) |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compare source code

2010-10-31 Thread Martin v. Loewis
> Should I be worry about this comment in reindent.py "So long as the
> input files get a clean bill of health from tabnanny.py, reindent should
> do a good job." ?

I don't think so: IIUC, this is about comments that are not reasonably
aligned with preceding or following code lines, most likely, you don't
have such comments in your files.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no line breaks in xml file with elementTree

2010-10-31 Thread Diez B. Roggisch
hackingKK  writes:

> On Sunday 31 October 2010 01:58 PM, Lawrence D'Oliveiro wrote:
>> In message, hackingKK
>> wrote:
>>
>>
>>> I want to know if there is a way to have the ElementTree module write to
>>> an xml file with line breaks?
>>>  
>> Why does it matter? The XML files you generate are not for humans to look
>> at, are they?
>>
>
> So is there a function to generate tags with namespace?

http://lmgtfy.com/?q=element+tree+namespac

--

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


Re: text file reformatting

2010-10-31 Thread cbr...@cbrownsystems.com
On Oct 31, 12:48 pm, Tim Chase  wrote:
> > PRJ01001 4 00100END
> > PRJ01002 3 00110END
>
> > I would like to pick only some columns to a new file and put them to a
> > certain places (to match previous data) - definition file (def.csv)
> > could be something like this:
>
> > VARIABLE   FIELDSTARTS     FIELD SIZE      NEW PLACE IN NEW DATA FILE
> > ProjID     ;       1       ;       5       ;       1
> > CaseID     ;       6       ;       3       ;       10
> > UselessV  ;        10      ;       1       ;
> > Zipcode    ;       12      ;       5       ;       15
>
> > So the new datafile should look like this:
>
> > PRJ01    001       00100END
> > PRJ01    002       00110END
>
> How flexible is the def.csv format?  The difficulty I see with
> your def.csv format is that it leaves undefined gaps (presumably
> to be filled in with spaces) and that you also have a blank "new
> place in new file" value.  If instead, you could specify the
> width to which you want to pad it and omit variables you don't
> want in the output, ordering the variables in the same order you
> want them in the output:
>
>   Variable; Start; Size; Width
>   ProjID; 1; 5; 10
>   CaseID; 6; 3; 10
>   Zipcode; 12; 5; 5
>   End; 16; 3; 3
>
> (note that I lazily use the same method to copy the END from the
> source to the destination, rather than coding specially for it)
> you could do something like this (untested)
>
>    import csv
>    f = file('def.csv', 'rb')
>    f.next() # discard the header row
>    r = csv.reader(f, delimiter=';')
>    fields = [
>      (varname, slice(int(start), int(start)+int(size)), width)
>      for varname, start, size, width
>      in r
>      ]
>    f.close()
>    out = file('out.txt', 'w')
>    try:
>      for row in file('data.txt'):
>        for varname, slc, width in fields:
>          out.write(row[slc].ljust(width))
>        out.write('\n')
>    finally:
>      out.close()
>
> Hope that's fairly easy to follow and makes sense.  There might
> be some fence-posting errors (particularly your use of "1" as the
> initial offset, while python uses "0" as the initial offset for
> strings)
>
> If you can't modify the def.csv format, then things are a bit
> more complex and I'd almost be tempted to write a script to try
> and convert your existing def.csv format into something simpler
> to process like what I describe.
>
> -tkc

To your point about the non-stand csv encoding in the defs.csv file,
you could use a reg exp instead of the csv module to solve that:

import re

parse_columns = re.compile(r'\s*;\s*')

f = file('defs.csv', 'rb')
f.readline() # discard the header row
r = (parse_columns.split(line.strip()) for line in f)
fields = [
 (varname, slice(int(start), int(start)+int(size), int(width) if
width else 0))
for varname, start, size, width in r
 ]
f.close()

which given the OP's csv produces for fields:

[('ProjID', slice(1, 6, 1)), ('CaseID', slice(6, 9, 10)), ('UselessV',
slice(10, 11, 0)), ('Zipcode', slice(12, 17, 15))]

and that should work with the remainder of your original code;
although perhaps the OP wants something else to happen when width is
omitted from the csv...

Cheers - Chas

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


Re: A bug for raw string literals in Py3k?

2010-10-31 Thread John Machin
On Oct 31, 11:23 pm, Yingjie Lan  wrote:
> > > So I suppose this is a bug?
>
> > It's not, see
>
> >http://docs.python.org/py3k/reference/lexical_analysis.html#literals
>
> > # Specifically, a raw string cannot end in a single backslash
>
> Thanks! That looks weird to me ... doesn't this contradict with:
>
> All backslashes in raw string literals are interpreted literally.
> (seehttp://docs.python.org/release/3.0.1/whatsnew/3.0.html):

All backslashes in syntactically-correct raw string literals are
interpreted literally.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: text file reformatting

2010-10-31 Thread Braden Faulkner

Sorry to clarify, I was having issues getting this to work. I'm relatively new 
to Python. Sorry for the miscommunication.

> Date: Sun, 31 Oct 2010 16:13:42 -0500
> From: python.l...@tim.thechases.com
> To: brad...@hotmail.com
> CC: python-list@python.org
> Subject: Re: text file reformatting
> 
> On 10/31/10 14:52, Braden Faulkner wrote:
> >> import csv
> >> f = file('def.csv', 'rb')
> >> f.next() # discard the header row
> >> r = csv.reader(f, delimiter=';')
> >> fields = [
> >>   (varname, slice(int(start), int(start)+int(size)), width)
> >>   for varname, start, size, width
> >>   in r
> >>   ]
> >> f.close()
> >> out = file('out.txt', 'w')
> >> try:
> >>   for row in file('data.txt'):
> >> for varname, slc, width in fields:
> >>   out.write(row[slc].ljust(width))
> >> out.write('\n')
> >> finally:
> >>   out.close()
> >
> > I also am having issues with this.
> 
> [top-posting fixed -- it's generally frowned upon in this 
> newsgroup/mailing-list and adherence to the preferences will tend 
> to get you a wider audience]
> 
> Are your issues with my code, or with the topic at hand?  If it's 
> my code, note my comment about it being untested.  If it's the 
> topic at hand, I recommend trying my code (or a variation 
> there-of after you've tested it).
> 
> -tkc
> 
> 
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eclipse/PyDev - BOM Lexical Error

2010-10-31 Thread Fabio Zadrozny
On Mon, Oct 4, 2010 at 5:03 AM, TheOne  wrote:
> Hi.
>
> I installed eclipse/pydev today.
> I created a pydev project and added python source files with utf-8
> BOM.
> Eclipse/Pydev reports lexical error :
>  Lexical error at line 1, column 1. Encountered: "\ufeff" (65279),
> after : ""
>
> I want the source files to have BOM character. How could I shut off
> this error msg?
>
> My eclipse is Helios, pydev version is 1.6.2.2010090812

Hi Daewon,

This was a bug in Pydev. It has been fixed (for 1.6.4). This is still
unreleased, but you can grab the nightly build with that fix already
incorporated (it should be pretty stable at this point).

See http://pydev.org/download.html for details on getting the nightly.

Cheers,

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


Re: text file reformatting

2010-10-31 Thread Tim Chase

On 10/31/10 14:52, Braden Faulkner wrote:

import csv
f = file('def.csv', 'rb')
f.next() # discard the header row
r = csv.reader(f, delimiter=';')
fields = [
  (varname, slice(int(start), int(start)+int(size)), width)
  for varname, start, size, width
  in r
  ]
f.close()
out = file('out.txt', 'w')
try:
  for row in file('data.txt'):
for varname, slc, width in fields:
  out.write(row[slc].ljust(width))
out.write('\n')
finally:
  out.close()


I also am having issues with this.


[top-posting fixed -- it's generally frowned upon in this 
newsgroup/mailing-list and adherence to the preferences will tend 
to get you a wider audience]


Are your issues with my code, or with the topic at hand?  If it's 
my code, note my comment about it being untested.  If it's the 
topic at hand, I recommend trying my code (or a variation 
there-of after you've tested it).


-tkc


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


Re: Compare source code

2010-10-31 Thread Alan Harris-Reid


 Hi jf,

I use Beyond Compare (by Scooter Software) for comparing text files and 
find it an indespensible tool.  You can configure it so that it ignores 
tabs/whitespace, or treats spaces and tabs as different characters.  Not 
sure if it will work with compiled .pyc files, though (but then you 
wouldn't want to edit those, would you?)


Regards,
Alan


On 19:59, jf wrote:

Hi,

I've a project with tabs and spaces mixed (yes I know it's bad).

I edit each file to remove tabs, but it's so easy to make a mistake.
Do you know a tools to compare the initial file with the cleaned one 
to know if the algorithms are the same ?

By comparing pyc files for example.

Thanks.




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


RE: text file reformatting

2010-10-31 Thread Braden Faulkner

I also am having issues with this.

> Date: Sun, 31 Oct 2010 14:48:09 -0500
> From: python.l...@tim.thechases.com
> To: iwawi...@gmail.com
> Subject: Re: text file reformatting
> CC: python-list@python.org
> 
> > PRJ01001 4 00100END
> > PRJ01002 3 00110END
> >
> > I would like to pick only some columns to a new file and put them to a
> > certain places (to match previous data) - definition file (def.csv)
> > could be something like this:
> >
> > VARIABLEFIELDSTARTS FIELD SIZE  NEW PLACE IN NEW DATA FILE
> > ProjID  ;   1   ;   5   ;   1
> > CaseID  ;   6   ;   3   ;   10
> > UselessV  ; 10  ;   1   ;
> > Zipcode ;   12  ;   5   ;   15
> >
> > So the new datafile should look like this:
> >
> > PRJ01001   00100END
> > PRJ01002   00110END
> 
> 
> How flexible is the def.csv format?  The difficulty I see with 
> your def.csv format is that it leaves undefined gaps (presumably 
> to be filled in with spaces) and that you also have a blank "new 
> place in new file" value.  If instead, you could specify the 
> width to which you want to pad it and omit variables you don't 
> want in the output, ordering the variables in the same order you 
> want them in the output:
> 
>   Variable; Start; Size; Width
>   ProjID; 1; 5; 10
>   CaseID; 6; 3; 10
>   Zipcode; 12; 5; 5
>   End; 16; 3; 3
> 
> (note that I lazily use the same method to copy the END from the 
> source to the destination, rather than coding specially for it) 
> you could do something like this (untested)
> 
>import csv
>f = file('def.csv', 'rb')
>f.next() # discard the header row
>r = csv.reader(f, delimiter=';')
>fields = [
>  (varname, slice(int(start), int(start)+int(size)), width)
>  for varname, start, size, width
>  in r
>  ]
>f.close()
>out = file('out.txt', 'w')
>try:
>  for row in file('data.txt'):
>for varname, slc, width in fields:
>  out.write(row[slc].ljust(width))
>out.write('\n')
>finally:
>  out.close()
> 
> Hope that's fairly easy to follow and makes sense.  There might 
> be some fence-posting errors (particularly your use of "1" as the 
> initial offset, while python uses "0" as the initial offset for 
> strings)
> 
> If you can't modify the def.csv format, then things are a bit 
> more complex and I'd almost be tempted to write a script to try 
> and convert your existing def.csv format into something simpler 
> to process like what I describe.
> 
> -tkc
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: text file reformatting

2010-10-31 Thread Tim Chase

PRJ01001 4 00100END
PRJ01002 3 00110END

I would like to pick only some columns to a new file and put them to a
certain places (to match previous data) - definition file (def.csv)
could be something like this:

VARIABLEFIELDSTARTS FIELD SIZE  NEW PLACE IN NEW DATA FILE
ProjID  ;   1   ;   5   ;   1
CaseID  ;   6   ;   3   ;   10
UselessV  ; 10  ;   1   ;
Zipcode ;   12  ;   5   ;   15

So the new datafile should look like this:

PRJ01001   00100END
PRJ01002   00110END



How flexible is the def.csv format?  The difficulty I see with 
your def.csv format is that it leaves undefined gaps (presumably 
to be filled in with spaces) and that you also have a blank "new 
place in new file" value.  If instead, you could specify the 
width to which you want to pad it and omit variables you don't 
want in the output, ordering the variables in the same order you 
want them in the output:


 Variable; Start; Size; Width
 ProjID; 1; 5; 10
 CaseID; 6; 3; 10
 Zipcode; 12; 5; 5
 End; 16; 3; 3

(note that I lazily use the same method to copy the END from the 
source to the destination, rather than coding specially for it) 
you could do something like this (untested)


  import csv
  f = file('def.csv', 'rb')
  f.next() # discard the header row
  r = csv.reader(f, delimiter=';')
  fields = [
(varname, slice(int(start), int(start)+int(size)), width)
for varname, start, size, width
in r
]
  f.close()
  out = file('out.txt', 'w')
  try:
for row in file('data.txt'):
  for varname, slc, width in fields:
out.write(row[slc].ljust(width))
  out.write('\n')
  finally:
out.close()

Hope that's fairly easy to follow and makes sense.  There might 
be some fence-posting errors (particularly your use of "1" as the 
initial offset, while python uses "0" as the initial offset for 
strings)


If you can't modify the def.csv format, then things are a bit 
more complex and I'd almost be tempted to write a script to try 
and convert your existing def.csv format into something simpler 
to process like what I describe.


-tkc


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


Re: Is there a way to pring a list object in Python?

2010-10-31 Thread Benjamin Kaplan
On Sun, Oct 31, 2010 at 3:04 PM, Zeynel  wrote:
>
>        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.
> --

Quite simple. You can apply a list method to a list object by actually
getting the list object. You can't call a list method on a query
object or a Rep object.

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

So once you have that last step, you have a list. Which you can
manipulate like any other Python list.
Once you have the list, you can call all them
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to pring a list object in Python?

2010-10-31 Thread Richard Thomas
On Oct 31, 7:04 pm, Zeynel  wrote:
> 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.

Okay that  is the representation of the object.
If you want to control how an object is represented when you put it in
a template you should define a __str__ method:

class Rep(db.model):
# Properties
...
# Representation
def __str__(self):
return "\n".join(self.replist)

Or however you want to object to appear. It may help to do a few
experiments outside GAE in the interactive interpreter.

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


Re: Is there a way to pring a list object in Python?

2010-10-31 Thread Zeynel
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


text file reformatting

2010-10-31 Thread iwawi
I have this fixed width data file (data.txt) which I would like to
reformat. Data is something like this, with hundreds of rows and
columns, every row finishes to END:

PRJ01001 4 00100END
PRJ01002 3 00110END
PRJ01003 3 00120END
PRJ01004 2 00130END
PRJ01005 1 00140END
PRJ01006 1 00150END
PRJ01007 3 00160END

I would like to pick only some columns to a new file and put them to a
certain places (to match previous data) - definition file (def.csv)
could be something like this:

VARIABLEFIELDSTARTS FIELD SIZE  NEW PLACE IN NEW DATA FILE
ProjID  ;   1   ;   5   ;   1
CaseID  ;   6   ;   3   ;   10
UselessV  ; 10  ;   1   ;
Zipcode ;   12  ;   5   ;   15

So the new datafile should look like this:

PRJ01001   00100END
PRJ01002   00110END
PRJ01003   00120END
PRJ01004   00130END
PRJ01005   00140END
PRJ01006   00150END
PRJ01007   00160END

If the datafile was as narrow as in this demofile, I would simply use
notepad to fix this, but there are more
than 100 variables I should pick and replace...

I'm missing the logic here - how it should be done?

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


Re: Py3: Import relative path module

2010-10-31 Thread Дамјан Георгиевски


> I am loathe to duplicate programming in files that should just load a
> copy from a module. I tried all kinds of tricks to import a module
> from one level up. What's the secret?
> 
> It works if I say:
> 
> from Data import DumpHT
> 
> but ONLY if the search path in sys.path. I want a relative path import
> independent from  sys.path.
> 
> How to? This is Python 3.1.1

from .. import Data.DumpHT as DumpHT


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Hi! I'm a .signature virus! copy me into your .signature file to help me 
spread!

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


Re: import ImageGrab fails on Ubuntu 10.4

2010-10-31 Thread News123
On 10/31/2010 05:04 PM, News123 wrote:

> importing ImageGrab un Ubuntu 10.4 fails as seen below:
> 
> import _grabscreen
> ImportError: No module named _grabscreen
> 


Well I found a partial answer on
http://www.pythonware.com/library/pil/handbook/imagegrab.htm

> The ImageGrab module can be used to copy the contents of the screen or the 
> clipboard to a PIL image memory.
> 
> The current version works on Windows only.


I just wonder why there is no cleaerer  message like

"platform not supported"


As a workaround I use now:

cmd = "import -window root %s" % fname
os.system(cmd)
img = Image.open(fname)

using the 'import' command of the ImageMagick tool kit

Is there any other way to make screen shots in Linux, ideally without
creating an intermediate file
-- 
http://mail.python.org/mailman/listinfo/python-list


import ImageGrab fails on Ubuntu 10.4

2010-10-31 Thread News123
Hi,

It's the first time I wanted to use ImageGrab.

importing ImageGrab fails as seen below:


$ python -c "import ImageGrab"
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/dist-packages/PIL/ImageGrab.py", line 34, in

import _grabscreen
ImportError: No module named _grabscreen
$


Is this an issue for all Ubuntu 10.4 releases or is this only failing on
my host?


Thanks in advance

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


Py3: Import relative path module

2010-10-31 Thread Gnarlodious
I am loathe to duplicate programming in files that should just load a
copy from a module. I tried all kinds of tricks to import a module
from one level up. What's the secret?

It works if I say:

from Data import DumpHT

but ONLY if the search path in sys.path. I want a relative path import
independent from  sys.path.

How to? This is Python 3.1.1

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


Re: Is there a way to pring a list object in Python?

2010-10-31 Thread Zeynel
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


Re: Compare source code

2010-10-31 Thread jf

Le 31/10/2010 13:10, Martin v. Loewis a écrit :

I've a project with tabs and spaces mixed (yes I know it's bad).

I edit each file to remove tabs, but it's so easy to make a mistake.
Do you know a tools to compare the initial file with the cleaned one to
know if the algorithms are the same ?


Tools/scripts/reindent.py of the standard Python distribution normalizes
white space in source code.


So great, you save my time !
Should I be worry about this comment in reindent.py "So long as the 
input files get a clean bill of health from tabnanny.py, reindent should 
do a good job." ?


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


Re: no line breaks in xml file with elementTree

2010-10-31 Thread Stefan Behnel

hackingKK, 31.10.2010 10:04:

On Sunday 31 October 2010 01:58 PM, Lawrence D'Oliveiro wrote:

hackingKK wrote:

Further more, I just was curious why elementtree is not having the
namespace facility?


ElementTree handles namespaces just fine.


So is there a function to generate tags with namespace?


Yes, it's called "Element", as in

el = ET.Element('{http://the.name/space}tag')

Reading the docs helps a lot here.

Stefan

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


Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
> > So I suppose this is a bug?
> 
> It's not, see
> 
> http://docs.python.org/py3k/reference/lexical_analysis.html#literals
> 
> # Specifically, a raw string cannot end in a single backslash

Thanks! That looks weird to me ... doesn't this contradict with:

All backslashes in raw string literals are interpreted literally.
(see http://docs.python.org/release/3.0.1/whatsnew/3.0.html):

Best,

Yingjie



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


Re: Compare source code

2010-10-31 Thread Martin v. Loewis
> I've a project with tabs and spaces mixed (yes I know it's bad).
> 
> I edit each file to remove tabs, but it's so easy to make a mistake.
> Do you know a tools to compare the initial file with the cleaned one to
> know if the algorithms are the same ?
> By comparing pyc files for example.

Tools/scripts/reindent.py of the standard Python distribution normalizes
white space in source code. It is used to maintain normalized
indentation in the Python library itself, but you can certainly use it
also for your own files :-)

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Compare source code

2010-10-31 Thread jf

Hi,

I've a project with tabs and spaces mixed (yes I know it's bad).

I edit each file to remove tabs, but it's so easy to make a mistake.
Do you know a tools to compare the initial file with the cleaned one to 
know if the algorithms are the same ?

By comparing pyc files for example.

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


Re: A bug for raw string literals in Py3k?

2010-10-31 Thread Martin v. Loewis
> So I suppose this is a bug?

It's not, see

http://docs.python.org/py3k/reference/lexical_analysis.html#literals

# Specifically, a raw string cannot end in a single backslash

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


A bug for raw string literals in Py3k?

2010-10-31 Thread Yingjie Lan
Hi,

I tried this in the IDLE (version 3.1.2) shell:

>>> r'\'
SyntaxError: EOL while scanning string literal

But according to the py3k docs 
(http://docs.python.org/release/3.0.1/whatsnew/3.0.html):

All backslashes in raw string literals are interpreted literally.

So I suppose this is a bug?

Yingjie


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


Re: Is there a way to pring a list object in Python?

2010-10-31 Thread Dave Angel

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

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


Re: no line breaks in xml file with elementTree

2010-10-31 Thread hackingKK

On Sunday 31 October 2010 01:58 PM, Lawrence D'Oliveiro wrote:

In message, hackingKK
wrote:

   

I want to know if there is a way to have the ElementTree module write to
an xml file with line breaks?
 

Why does it matter? The XML files you generate are not for humans to look
at, are they?
   


So is there a function to generate tags with namespace?

happy hacking.
Krishnakant.

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


Re: no line breaks in xml file with elementTree

2010-10-31 Thread Lawrence D'Oliveiro
In message , hackingKK 
wrote:

> I want to know if there is a way to have the ElementTree module write to
> an xml file with line breaks?

Why does it matter? The XML files you generate are not for humans to look 
at, are they?

> Further more, I just was curious why elementtree is not having the
> namespace facility?

ElementTree handles namespaces just fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


playing with berp: python3 to haskell compiler in haskell

2010-10-31 Thread Alia Khouri
In case anyone finds this worthwhile: there is a pretty impressive
python3 to haskell compiler written in haskell called berp that looks
very interesting: http://github.com/bjpop/berp/wiki

I highly recommend reading through the berp implementation code for a
fascinating (but currently incomplete) attempt at a purely functional
implementation of python3. The current version doesn't do floats and
imports and other things but includes callcc continuations and tail-
call optimization, and it is likely these things will be added
relatively quickly as the code is extremely well-structured.

Even the generated code (minus the underscore) is surprisingly
readable:


class Person:
def __init__(self, name):
self.name = name

def say_hello(self):
print('hello, my name is '+self.name)

def main():
p = Person('sam')
p.say_hello()

main()


to


module Main where
import Berp.Base
import qualified Prelude
main = runStmt init
init
  = do _s_Person <- var "Person"
   _s_main <- var "main"
   klass "Person" _s_Person []
 (do _s___init__ <- var "__init__"
 _s_say_hello <- var "say_hello"
 def _s___init__ 2 none
   (\ [_s_self, _s_name] ->
  do _t_0 <- read _s_name
 _t_1 <- read _s_self
 setattr _t_1 (621807930, "_s_name") _t_0)
 def _s_say_hello 1 none
   (\ [_s_self] ->
  do _t_2 <- read _s_print
 _t_3 <- read _s_self
 _t_4 <- _t_3 . (621807930, "_s_name")
 _t_5 <- string "hello, my name is " + _t_4
 _t_2 @@ [_t_5])
 pure
   [((-277916325, "_s___init__"), _s___init__),
((175397596, "_s_say_hello"), _s_say_hello)])
   def _s_main 0 none
 (\ [] ->
do _s_p <- var "p"
   _t_6 <- read _s_Person
   _t_7 <- _t_6 @@ [string "sam"]
   _s_p =: _t_7
   _t_8 <- read _s_p
   _t_9 <- _t_8 . (175397596, "_s_say_hello")
   _t_9 @@ [])
   _t_10 <- read _s_main
   _t_10 @@ []





Also see: others ways to interface to haskell code (from ctypes for
example, see my entry in http://wiki.python.org/moin/PythonVsHaskell)

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


no line breaks in xml file with elementTree

2010-10-31 Thread hackingKK

Hello all.
I want to know if there is a way to have the ElementTree module write to 
an xml file with line breaks?
I find that when I use the write function from the module on a tree 
object, the resulting file has no line breaks.  I don't want to use 
prittyprint because it is adding extra tabs to the file and they are 
either counted as extra nodes or in case of element.text with 
elementtree, they are rendered as a part of the text, both being 
impractical results.
So is there a middle approach where we can have some  thing similar to 
prityprint but without the extra tabs and yet having a properly line 
breaked xml file?
Further more, I just was curious why elementtree is not having the 
namespace facility?

xml.dom.minidom has a way to generate tags with namespaces.
Any thing similar in elementTree?

happy hacking.
Krishnakant.



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


Re: Is there a way to pring a list object in Python?

2010-10-31 Thread Richard Thomas
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.
-- 
http://mail.python.org/mailman/listinfo/python-list