Re: Separate Rows in reader

2013-03-24 Thread rusi
On Mar 24, 10:46 am, Dave Angel  wrote:
> On 03/24/2013 01:20 AM, Jiewei Huang wrote:
>
>
>
>
>
>
>
>
>
> > Hi all,
>
> > Currently create a simple text-based database of information about people
>
> > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such:
> > Name        Address        Telephone       Birthday
> > John Konon Ministry of Moon Walks  4567882 27-Feb
> > Stacy Kisha        Ministry of Man Power   1234567 17-Jan
>
> > My codes are :
> > import csv
> > original = file('friends.csv', 'rU')
> > reader = csv.reader(original)
>
> > for row in reader:
>
> >      print row
>
> > and the output is :
> > ['Name', ' Address', 'Telephone', 'Birthday']
> > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb']
> > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan']
>
> > But i wanted to make it
>
> > [('John Cleese', 'Ministry of Silly Walks', '421', '27-Feb'),
> > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
>
> > can someone show me guidance to this issue
>
> > Thanks all
>
> There are at least 3 differences to the printouts.  Which difference are
> you concerned with?
>
> 1) Moon --> Silly
> 2) square and round brackets in slightly different places
> 3) row 0 suppressed
>
> Explain which one, or specify a fourth, and also what you have tried to
> address the question.
>
> --
> DaveA

Besides does it work as you are describing?
ie your input appears to be tab delimited, whereas the default is ','
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SOAPpy.Types.faultType: Cannot use object of type stdClass as array

2013-03-24 Thread Tamer Higazi
Hi Chris!
The example from the website is buggy because the WSDL urls are not
correct...

$WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl'
$WSDL_API ='https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl'

which I had replaced so far.

then you will see the results, even if the login and pass do not match.

I think for many python developers it might be really interesting to
know, WHAT A PHP ARRAY is in python in a SOAP environment.





Tamer


Am 23.03.2013 21:55, schrieb Chris Angelico:
> On Sun, Mar 24, 2013 at 6:38 AM, Tamer Higazi  wrote:
>> Chris!
>> I did what you said before in several ways.
>>
>> The last way was putting the user and password directly into the dict as
>> parameter ALWAYS ends up telling me, that I cannot use object of
>> standard type class as ARRAY
>>
>> I did it this time with suds. So packaging issue is now out of scope,
>> and always the same headache.
>>
>>
>> now tell me what this error might tell me:
>>
>>
>> suds.WebFault: Server raised fault: 'Cannot use object of type stdClass
>> as array'
> 
> So it's the same error this way, too. That error came back from the
> server, and is being quoted verbatim. That means that, ultimately, the
> problem is in the XML blob that you're sending it; the trick is to
> figure out what exactly the server isn't happy with.
> 
> (Aside: The server is at least partly at fault here. It should be
> giving more useful error messages. But I'm assuming you don't have any
> control over the server.)
> 
> I tried the reference PHP implementation off the web site, and it's
> coming back with 500 Internal Server Error with body of text/html,
> which is clearly buggy documentation. When I change it to use the WSDL
> you're using, I can actually get something plausible out of it.
> 
> Modified PHP code:
> 
>  
> // URIs zu den WSDL-Dateien
> $WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl';
> //$WSDL_API = 'https://kasserver.com/schnittstelle/soap/wsdl/KasApi.wsdl';
> 
> // Logindaten
> $kas_user = 'w001234';  // KAS-Logon
> $kas_pass = 'xxx';  // KAS-Passwort
> $session_lifetime = 1800;  // Gültigkeit des Tokens in Sek. bis zur
> neuen Authentifizierung
> $session_update_lifetime = 'Y'; // Soll bei jeder Aktion die
> Sessionlifetime wieder auf den
> //   Wert in "$session_lifetime"
> gesetzt werden? ('Y' / 'N')
> try
> {
>   $SoapLogon = new SoapClient($WSDL_AUTH,["trace"=>1]);  // url zur wsdl - 
> Datei
>   $CredentialToken = $SoapLogon->KasAuth(
>   array('KasUser' => $kas_user,
> 'KasAuthType' => 'sha1',
> 'KasPassword' => sha1($kas_pass),
> 'SessionLifeTime' => $session_lifetime,
> 'SessionUpdateLifeTime' =>
> $session_update_lifetime
>   )
> );
> }
> 
> // Fehler abfangen und ausgeben
> catch (SoapFault $fault)
> {
> echo 
> "Request:\n".$SoapLogon->__getLastRequestHeaders()."\n".$SoapLogon->__getLastRequest()."\n";
> echo 
> "Response:\n".$SoapLogon->__getLastResponseHeaders()."\n".$SoapLogon->__getLastResponse()."\n";
> trigger_error("Fehlernummer: {$fault->faultcode},
> Fehlermeldung: {$fault->faultstring},
> Verursacher: {$fault->faultactor},
> Details: {$fault->detail}", E_USER_ERROR);
> }
> 
> 
> 
> (Another aside: Until I added the two echo lines, this had a try/catch
> that simply triggered a fatal error. This is pointless. Just let the
> error happen!)
> 
> Here's the packet the PHP code sends:
> 
> 
>  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
> xmlns:ns1="urn:xmethodsKasApiAuthentication"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns:xsd="http://www.w3.org/2001/XMLSchema";
> xmlns:ns2="http://xml.apache.org/xml-soap";
> xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/";
> SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";> xsi:type="ns2:Map"> xsi:type="xsd:string">KasUser xsi:type="xsd:string">w001234 xsi:type="xsd:string">KasAuthType xsi:type="xsd:string">sha1 xsi:type="xsd:string">KasPassword xsi:type="xsd:string">2db6d21d365f544f7ca3bcfb443ac96898a7a069 xsi:type="xsd:string">SessionLifeTime xsi:type="xsd:int">1800 xsi:type="xsd:string">SessionUpdateLifeTime xsi:type="xsd:string">Y
> 
> Here's what your original Python version sends, lifted via tcpdump as
> I'm not sufficiently familiar with soappy to get a full packet dump
> out of it:
> 
>SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
>   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/";
>   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
>   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
>   xmlns:xsd="http://www.w3.org/1999/XMLSchema";
>>
> 
> 
> 
> Y
> sha1
> 1800
> login
>  xsi:type="xsd:string">5baa61e4c9b93f3f0682250b

Re: addressof object with id()

2013-03-24 Thread Peter Otten
Steven D'Aprano wrote:

> On Sat, 23 Mar 2013 21:00:07 -0400, Roy Smith wrote:
> 
>> In article ,
>>  Fabian von Romberg  wrote:
>> 
>>> Hi,
>>> 
>>> I have a single questions regarding id() built-in function.
>>> 
>>> example 1:
>>> 
>>> var1 = "some string"
>>> var2 = "some string"
>>> 
>>> if use the id() function on both, it returns exactly the same address.
>> 
>> Yup.
> 
> Nope. Did you actually try it?
> 
> 
> As far as I know, there is no Python implementation that automatically
> interns strings which are not valid identifiers. "some string" is not a
> valid identifier, due to the space.


I don't know about other implementations, but in CPython two equal strings 
in the *same* *compilation* will end up with the same id as a result of 
constant folding. In the interpreter:

>>> a = "some string"
>>> b = "some string"
>>> a is b
False
>>> a = "some string"; b = "some string"; a is b
True

In a script:

$ cat tmp.py
a = "some string"
b = "some string"
print a is b
$ python tmp.py
True


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


Re: Separate Rows in reader

2013-03-24 Thread Jiewei Huang
On Sunday, March 24, 2013 3:46:49 PM UTC+10, Dave Angel wrote:
> On 03/24/2013 01:20 AM, Jiewei Huang wrote:
> 
> > Hi all,
> 
> >
> 
> > Currently create a simple text-based database of information about people
> 
> >
> 
> >
> 
> > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such:
> 
> > Name AddressTelephone   Birthday
> 
> > John Konon  Ministry of Moon Walks  4567882 27-Feb
> 
> > Stacy Kisha Ministry of Man Power   1234567 17-Jan
> 
> >
> 
> >
> 
> > My codes are :
> 
> > import csv
> 
> > original = file('friends.csv', 'rU')
> 
> > reader = csv.reader(original)
> 
> >
> 
> > for row in reader:
> 
> >
> 
> >  print row
> 
> >
> 
> >
> 
> > and the output is :
> 
> > ['Name', ' Address', 'Telephone', 'Birthday']
> 
> > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb']
> 
> > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan']
> 
> >
> 
> > But i wanted to make it
> 
> >
> 
> > [('John Cleese', 'Ministry of Silly Walks', '421', '27-Feb'),
> 
> > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
> 
> >
> 
> > can someone show me guidance to this issue
> 
> >
> 
> > Thanks all
> 
> >
> 
> 
> 
> There are at least 3 differences to the printouts.  Which difference are 
> 
> you concerned with?
> 
> 
> 
> 1) Moon --> Silly
> 
> 2) square and round brackets in slightly different places
> 
> 3) row 0 suppressed
> 
> 
> 
> Explain which one, or specify a fourth, and also what you have tried to 
> 
> address the question.
> 
> 
> 
> 
> 
> -- 
> 
> DaveA


Sorry my typo in the output here is the correct output that i need :

[('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), 
( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] 

the difference is that i need a [(row two), (row three), (row fouth)] . I do 
not want to display row one which is ['Name', ' Address', 'Telephone', 
'Birthday'] 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Separate Rows in reader

2013-03-24 Thread Jiewei Huang
On Sunday, March 24, 2013 5:34:03 PM UTC+10, rusi wrote:
> On Mar 24, 10:46 am, Dave Angel  wrote:
> 
> > On 03/24/2013 01:20 AM, Jiewei Huang wrote:
> 
> >
> 
> >
> 
> >
> 
> >this is the data in csv file http://imgur.com/L4qUkGQ
and this is the correct output that i need to get:
[('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), 
( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] 
sorry for the confusion 

> 
> >
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > > Hi all,
> 
> >
> 
> > > Currently create a simple text-based database of information about people
> 
> >
> 
> > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such:
> 
> > > Name        Address        Telephone       Birthday
> 
> > > John Konon Ministry of Moon Walks  4567882 27-Feb
> 
> > > Stacy Kisha        Ministry of Man Power   1234567 17-Jan
> 
> >
> 
> > > My codes are :
> 
> > > import csv
> 
> > > original = file('friends.csv', 'rU')
> 
> > > reader = csv.reader(original)
> 
> >
> 
> > > for row in reader:
> 
> >
> 
> > >      print row
> 
> >
> 
> > > and the output is :
> 
> > > ['Name', ' Address', 'Telephone', 'Birthday']
> 
> > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb']
> 
> > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan']
> 
> >
> 
> > > But i wanted to make it
> 
> >
> 
> > > [('John Cleese', 'Ministry of Silly Walks', '421', '27-Feb'),
> 
> > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
> 
> >
> 
> > > can someone show me guidance to this issue
> 
> >
> 
> > > Thanks all
> 
> >
> 
> > There are at least 3 differences to the printouts.  Which difference are
> 
> > you concerned with?
> 
> >
> 
> > 1) Moon --> Silly
> 
> > 2) square and round brackets in slightly different places
> 
> > 3) row 0 suppressed
> 
> >
> 
> > Explain which one, or specify a fourth, and also what you have tried to
> 
> > address the question.
> 
> >
> 
> > --
> 
> > DaveA
> 
> 
> 
> Besides does it work as you are describing?
> 
> ie your input appears to be tab delimited, whereas the default is ','
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: addressof object with id()

2013-03-24 Thread Steven D'Aprano
On Sun, 24 Mar 2013 06:54:08 +, Nobody wrote:

> More generally, an implementation *may* intern any immutable value,
> although it's not guaranteed to do so for anything except (IIRC) False,
> True and None.

I believe the same also applies to NotImplemented and Ellipsis, although 
I'm too lazy to look them up to check for sure.



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


Re: Separate Rows in reader

2013-03-24 Thread ypsun
Jiewei Huang於 2013年3月24日星期日UTC+1上午6時20分29秒寫道:
> Hi all,
> 
> 
> 
> Currently create a simple text-based database of information about people
> 
>  
> 
> 
> 
> I have a csv file which consist of 3 rows , row 1 2 and 3 is as such:
> 
> Name   AddressTelephone   Birthday  
> 
> John KononMinistry of Moon Walks  4567882 27-Feb
> 
> Stacy Kisha   Ministry of Man Power   1234567 17-Jan
> 
> 
> 
> 
> 
> My codes are :
> 
> import csv
> 
> original = file('friends.csv', 'rU')
> 
> reader = csv.reader(original)
> 
> 
> 
> for row in reader:
> 
> 
> 
> print row
> 
> 
> 
> 
> 
> and the output is :
> 
> ['Name', ' Address', 'Telephone', 'Birthday']
> 
> ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb']
> 
> ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan']
> 
> 
> 
> But i wanted to make it
> 
> 
> 
> [('John Cleese', 'Ministry of Silly Walks', '421', '27-Feb'),
> 
> ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
> 
> 
> 
> can someone show me guidance to this issue
> 
> 
> 
> Thanks all

import csv 
original = file('friends.csv', 'rU')
reader = csv.reader(original) 

result = []
for row in reader:
result.append(tuple(row))
else:
print result[1:]


Is this what you need?
but this allocates memory and will be a trouble when you have a big table :P
Note that I assume your csv file content are comma seperated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Separate Rows in reader

2013-03-24 Thread ypsun
Jiewei Huang於 2013年3月24日星期日UTC+1上午6時20分29秒寫道:
> Hi all,
> 
> 
> 
> Currently create a simple text-based database of information about people
> 
>  
> 
> 
> 
> I have a csv file which consist of 3 rows , row 1 2 and 3 is as such:
> 
> Name   AddressTelephone   Birthday  
> 
> John KononMinistry of Moon Walks  4567882 27-Feb
> 
> Stacy Kisha   Ministry of Man Power   1234567 17-Jan
> 
> 
> 
> 
> 
> My codes are :
> 
> import csv
> 
> original = file('friends.csv', 'rU')
> 
> reader = csv.reader(original)
> 
> 
> 
> for row in reader:
> 
> 
> 
> print row
> 
> 
> 
> 
> 
> and the output is :
> 
> ['Name', ' Address', 'Telephone', 'Birthday']
> 
> ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb']
> 
> ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan']
> 
> 
> 
> But i wanted to make it
> 
> 
> 
> [('John Cleese', 'Ministry of Silly Walks', '421', '27-Feb'),
> 
> ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
> 
> 
> 
> can someone show me guidance to this issue
> 
> 
> 
> Thanks all

import csv
original = file('friends.csv', 'rU')
reader = csv.reader(original)
print [tuple(row) for row in reader][1:]

is this you want?
Note that:
1) I assume your csv file content are seperated by comma
2) this way allocates your memory, will be a trouble when a big table :P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Separate Rows in reader

2013-03-24 Thread Dave Angel

On 03/24/2013 04:11 AM, Jiewei Huang wrote:







Sorry my typo in the output here is the correct output that i need :

[('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'),
( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]

the difference is that i need a [(row two), (row three), (row fouth)] . I do 
not want to display row one which is ['Name', ' Address', 'Telephone', 
'Birthday']



I had to add a delimiter= to accomodate the fact that your data is tab- 
separated.


The first two code sections address the dropping of row-zero.
The third section changes the square brackets to parens, if that's what 
you really wanted.
The fourth section goes all around the barn to get the linefeeds in the 
right place.  There's still one extra space on the first line, but 
that's an exercise for the reader.


run with CPython 2.7.3

import csv

original = [
"Name   AddressTelephone   Birthday  ",
"John KononMinistry of Moon Walks  4567882 27-Feb",
"Stacy Kisha   Ministry of Man Power   1234567 17-Jan"
]

#original = file('friends.csv', 'rU')
reader = csv.reader(original, delimiter="\t")
for index, row in enumerate(reader):
if index:
print row
print "---"

reader = csv.reader(original, delimiter="\t")
data = list(reader)[1:]
print data
print "---"

reader = csv.reader(original, delimiter="\t")
data = [tuple(row) for row in list(reader)[1:]]
print data
print "---"

reader = csv.reader(original, delimiter="\t")
data = [tuple(row) for row in list(reader)[1:]]
print "[",
for row in data[:-1]:
print str(row) + ","
print str(data[-1]) +"]"
print "---"


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


Re: "monty" < "python"

2013-03-24 Thread jmfauth
On 23 mar, 17:17, Mark Lawrence  wrote:
> On 23/03/2013 09:24, jmfauth wrote:
>
>
>
>
>
>
>
>
>
> > On 20 mar, 22:02, Tim Delaney  wrote:
> >> On 21 March 2013 06:40, jmfauth  wrote:
>
> >>> 
> >>> [snip usual rant from jmf]
>
> >> It has been acknowledged as a real regression, but he keeps hijacking every
> >> thread where strings are mentioned to harp on about it. He has shown no
> >> inclination to attempt to *fix* the regression and is rapidly coming to be
> >> regarded as a troll by most participants in this list.
>
> > -
>
> > I can not help to fix it, because it is "unfixable". It
> > is "unfixable", because this flexible string representation
> > is wrong by design.
>
> > jmf
>
> Of course it's fixable.  All you need do is write a PEP clearing stating
> what is wrong with the implementation detailed in PEP393 and your own
> proposed design.  I'm looking forward to reading this PEP.
>
> Note that going backwards to buggier unicode implementations that
> existed in Python prior to version 3.3 is simply not an option.
>
> --
> Cheers.
>
> Mark Lawrence

--

The problem here is that this PEP 393 should not have been
created.
The first time I read it, I quickly understood, it can
not work!

This is illustrated by all the examples I give on this list.
In all the cases, I can explain why.

I never saw somebody beeing able to argue these examples are
wrong and/or explaining why they are wrong, except arguing
the flexible string representation exists!

jmf

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


Re: "monty" < "python"

2013-03-24 Thread Chris Angelico
On Mon, Mar 25, 2013 at 12:31 AM, jmfauth  wrote:
> The problem here is that this PEP 393 should not have been
> created.
> The first time I read it, I quickly understood, it can
> not work!

I fail to understand how something can "not work" when it is clearly
working, and very successfully too, in two different languages. All of
your complaints have been on the basis of *timings*, which really
means you're complaining about performance, not correctness. If you
can show any evidence that something actually is not *working*, please
do so (in a fresh thread, not in a hijacked one).

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


Re: Separate Rows in reader

2013-03-24 Thread Tim Chase
On 2013-03-24 09:03, Dave Angel wrote:
> >> 

[THANK YOU!]

> > Sorry my typo in the output here is the correct output that i
> > need :
> >
> > [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'),
> > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
> >
> > the difference is that i need a [(row two), (row three), (row
> > fouth)] . I do not want to display row one which is ['Name', '
> > Address', 'Telephone', 'Birthday']
> 
> I had to add a delimiter= to accomodate the fact that your data is
> tab- separated.

Since it has headers, it might make more sense for readability to use
a DictReader:

  f = file("source.txt", "rb")
  r = csv.DictReader(f, delimiter='\t')
  for row in r:
print row["Name"], row["Address"], ...

However, if it's just stripping off the first row and operating
directly on the resulting data, then I'd just be tempted to do

  r = csv.reader(f, delimiter='\t')
  r.next() # discard the headers, or optionally store them
  for row in r:
...

-tkc



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


Re: "monty" < "python"

2013-03-24 Thread Mark Lawrence

On 24/03/2013 13:31, jmfauth wrote:


The problem here is that this PEP 393 should not have been
created.
The first time I read it, I quickly understood, it can
not work!


How come you couldn't pursuade the Python devs that PEP393 was so flawed?



This is illustrated by all the examples I give on this list.
In all the cases, I can explain why.


IIRC you've never said that the implementation doesn't work.   You've 
repeatedly given micro benchmarks regarding performance and nothing else.




I never saw somebody beeing able to argue these examples are
wrong and/or explaining why they are wrong, except arguing
the flexible string representation exists!


Sheer unadultered crap.  Was your education at the Dr Goebbels Institute?



jmf




--
Cheers.

Mark Lawrence

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


Re: Vowels [was Re: "monty" < "python"]

2013-03-24 Thread Stefan Behnel
Terry Reedy, 22.03.2013 00:05:
> I never imagined that there were people who would mix up 'tuner' and
> 'tuna'. Live and learn.

I assume you know "The Chaos" ?

http://ncf.idallen.com/english.html

Stefan


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


Re: Vowels [was Re: "monty" < "python"]

2013-03-24 Thread rusi
On Mar 24, 7:25 pm, Stefan Behnel  wrote:
>
> I assume you know "The Chaos" ?
>
> http://ncf.idallen.com/english.html

Ha! Sweet! (Or should I say suet?)
-- 
http://mail.python.org/mailman/listinfo/python-list


ImportError: No module named multipli

2013-03-24 Thread yahya Kacem
Hi, i have this 2 files:

file named multipli:

#!/usr/bin/python3.2
#-* - coding : utf-8 -*
def table(nb, max):
  i = 0
  while i < max:
print(i + 1, " * ", nb, "= ", (i + 1) * nb)

and file naled test:

#!/usr/bin/python3.2
# -* - coding : utf-8 -*
import os
import sys
from multipli import table
table(3, 20)
os.system("pause")

when i run this:

python3 test

I get this error:
Traceback (most recent call last):
  File "test", line 5, in 
from multipli import table
ImportError: No module named multipli 
both files are in the same directory.
any help thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named multipli

2013-03-24 Thread Kwpolska
On Sun, Mar 24, 2013 at 4:35 PM, yahya Kacem  wrote:
> Hi, i have this 2 files:
>
> file named multipli:
>
> #!/usr/bin/python3.2
> #-* - coding : utf-8 -*
> def table(nb, max):
>   i = 0
>   while i < max:
> print(i + 1, " * ", nb, "= ", (i + 1) * nb)
>
> and file naled test:
>
> #!/usr/bin/python3.2
> # -* - coding : utf-8 -*
> import os
> import sys
> from multipli import table
> table(3, 20)
> os.system("pause")
>
> when i run this:
>
> python3 test
>
> I get this error:
> Traceback (most recent call last):
>   File "test", line 5, in 
> from multipli import table
> ImportError: No module named multipli
> both files are in the same directory.
> any help thanks in advance.
> --
> http://mail.python.org/mailman/listinfo/python-list

make them test.py and multipli.py.

-- 
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named multipli

2013-03-24 Thread Chris Angelico
On Mon, Mar 25, 2013 at 2:35 AM, yahya Kacem  wrote:
> file named multipli:
>
> and file naled test:
>
> from multipli import table

Try naming it multipli.py

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


Re: Separate Rows in reader

2013-03-24 Thread rusi
On Mar 24, 6:49 pm, Tim Chase  wrote:
> On 2013-03-24 09:03, Dave Angel wrote:
>
> > >> 
>
> [THANK YOU!]
>
> > > Sorry my typo in the output here is the correct output that i
> > > need :
>
> > > [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'),
> > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
>
> > > the difference is that i need a [(row two), (row three), (row
> > > fouth)] . I do not want to display row one which is ['Name', '
> > > Address', 'Telephone', 'Birthday']
>
> > I had to add a delimiter= to accomodate the fact that your data is
> > tab- separated.
>
> Since it has headers, it might make more sense for readability to use
> a DictReader:
>
>   f = file("source.txt", "rb")
>   r = csv.DictReader(f, delimiter='\t')
>   for row in r:
>     print row["Name"], row["Address"], ...
>
> However, if it's just stripping off the first row and operating
> directly on the resulting data, then I'd just be tempted to do
>
>   r = csv.reader(f, delimiter='\t')
>   r.next() # discard the headers, or optionally store them
>   for row in r:
>     ...
>
> -tkc

After doing:

>>> import csv
>>> original = file('friends.csv', 'rU')
>>> reader = csv.reader(original, delimiter='\t')


Stripping of the first line is:
>>> list(reader)[1:]

If for some reason you want to tuplify each row do either:
>>> [tuple(row) for row in list(reader)[1:]]

Or else
>>> map(tuple,list(reader)[1:])

I usually prefer comprehensions to maps. Here though, the map is
shorter. Your choice


Then you can of course make your code more performant thus:
>>> reader.next()
>>> (tuple(row) for row in reader)

In the majority of cases this optimization is not worth it
In any case, strewing prints all over the code is a bad habit (except
for debugging).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named multipli

2013-03-24 Thread yahya Kacem
On Sunday, March 24, 2013 4:35:29 PM UTC+1, yahya Kacem wrote:
> Hi, i have this 2 files:
> 
> 
> 
> file named multipli:
> 
> 
> 
> #!/usr/bin/python3.2
> 
> #-* - coding : utf-8 -*
> 
> def table(nb, max):
> 
>   i = 0
> 
>   while i < max:
> 
> print(i + 1, " * ", nb, "= ", (i + 1) * nb)
> 
> 
> 
> and file naled test:
> 
> 
> 
> #!/usr/bin/python3.2
> 
> # -* - coding : utf-8 -*
> 
> import os
> 
> import sys
> 
> from multipli import table
> 
> table(3, 20)
> 
> os.system("pause")
> 
> 
> 
> when i run this:
> 
> 
> 
> python3 test
> 
> 
> 
> I get this error:
> 
> Traceback (most recent call last):
> 
>   File "test", line 5, in 
> 
> from multipli import table
> 
> ImportError: No module named multipli 
> 
> both files are in the same directory.
> 
> any help thanks in advance.

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


Re: ImportError: No module named multipli

2013-03-24 Thread Mark Lawrence

On 24/03/2013 15:48, Chris Angelico wrote:

On Mon, Mar 25, 2013 at 2:35 AM, yahya Kacem  wrote:

file named multipli:

and file naled test:

 from multipli import table


Try naming it multipli.py

ChrisA



Before or after fixing the infinite loop? :)

--
Cheers.

Mark Lawrence

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


Re: Vowels [was Re: "monty" < "python"]

2013-03-24 Thread Mark Lawrence

On 24/03/2013 14:25, Stefan Behnel wrote:

Terry Reedy, 22.03.2013 00:05:

I never imagined that there were people who would mix up 'tuner' and
'tuna'. Live and learn.


I assume you know "The Chaos" ?

http://ncf.idallen.com/english.html

Stefan




For many years I've felt it was wrong that people apologised for their 
poor English.  Having read the above link I feel compelled to state, 
please do not apologise for your poor English.


--
Cheers.

Mark Lawrence

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


Re: ImportError: No module named multipli

2013-03-24 Thread Chris Angelico
On Mon, Mar 25, 2013 at 3:10 AM, Mark Lawrence  wrote:
> On 24/03/2013 15:48, Chris Angelico wrote:
>>
>> On Mon, Mar 25, 2013 at 2:35 AM, yahya Kacem  wrote:
>>>
>>> file named multipli:
>>>
>>> and file naled test:
>>>
>>>  from multipli import table
>>
>>
>> Try naming it multipli.py
>>
>> ChrisA
>>
>
> Before or after fixing the infinite loop? :)

Before. Then you run it, see it spew text to the console, and hit Ctrl-C.

Programming is iterative: once you fix one problem, you find the next.
Programming is also recursive: in fixing one problem, you sometimes
have to deal with others that it depends on. Programming is
functional, too: you take a list of problems, apply the "Code"
function to them, and keep the list of return values, which will be
hopefully-working code. And programming is object-oriented... whatever
you do, someone will object to it.

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


Re: ImportError: No module named multipli

2013-03-24 Thread Mark Lawrence

On 24/03/2013 16:03, yahya Kacem wrote:

On Sunday, March 24, 2013 4:35:29 PM UTC+1, yahya Kacem wrote:

Hi, i have this 2 files:



file named multipli:



 #!/usr/bin/python3.2

 #-* - coding : utf-8 -*

 def table(nb, max):

   i = 0

   while i < max:

 print(i + 1, " * ", nb, "= ", (i + 1) * nb)



and file naled test:



 #!/usr/bin/python3.2

 # -* - coding : utf-8 -*

 import os

 import sys

 from multipli import table

 table(3, 20)

 os.system("pause")



when i run this:



 python3 test



I get this error:

 Traceback (most recent call last):

   File "test", line 5, in 

 from multipli import table

 ImportError: No module named multipli

both files are in the same directory.

any help thanks in advance.


Thanks that did it.



May I ask what did it?

Please read this as it helps prevent the bill from my optician soaring 
http://wiki.python.org/moin/GoogleGroupsPython


--
Cheers.

Mark Lawrence

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


i need advice

2013-03-24 Thread leonardo selmi
dear python programmers,

i am focused on learning to program but i need help from all of you. i am a 
beginner but it is hard to find the right book or website to learn, i know that 
i have to do exercises but so far i found resources with gaps. i would be very 
grateful if you could give me suggestions. for example i have "think python" 
and "learning python the hard way", do you recommend them or are there better 
books?

thanks a lot and sorry for bugging you

best regards

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


Re: i need advice

2013-03-24 Thread Joel Goldstick
On Sun, Mar 24, 2013 at 1:24 PM, leonardo selmi  wrote:

> dear python programmers,
>
> i am focused on learning to program but i need help from all of you. i am
> a beginner but it is hard to find the right book or website to learn, i
> know that i have to do exercises but so far i found resources with gaps. i
> would be very grateful if you could give me suggestions. for example i have
> "think python" and "learning python the hard way", do you recommend them or
> are there better books?
>
> thanks a lot and sorry for bugging you
>
> best regards
>

Start here: http://www.python.org/about/help/ and especially
http://wiki.python.org/moin/BeginnersGuide

Everyone learns in their own way so keep trying different resources until
you find what works best for you.

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



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: i need advice

2013-03-24 Thread Mark Lawrence

On 24/03/2013 17:24, leonardo selmi wrote:

dear python programmers,

i am focused on learning to program but i need help from all of you. i am a beginner but it is hard 
to find the right book or website to learn, i know that i have to do exercises but so far i found 
resources with gaps. i would be very grateful if you could give me suggestions. for example i have 
"think python" and "learning python the hard way", do you recommend them or are 
there better books?

thanks a lot and sorry for bugging you

best regards

leonardo



Start here http://wiki.python.org/moin/BeginnersGuide ?

--
Cheers.

Mark Lawrence

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


Re: i need advice

2013-03-24 Thread Omer
I know some people will disagree with me, but I recommend on "Dive Into
 Python" by Mark Pilgrim. It assumes no prior knowledge whatsoever, and it
explains all the foundations of the language from the bottom up, without
skipping any steps. It also provides many examples that demonstrate how to
get Python to do things.


On 24 March 2013 19:24, leonardo selmi  wrote:

> dear python programmers,
>
> i am focused on learning to program but i need help from all of you. i am
> a beginner but it is hard to find the right book or website to learn, i
> know that i have to do exercises but so far i found resources with gaps. i
> would be very grateful if you could give me suggestions. for example i have
> "think python" and "learning python the hard way", do you recommend them or
> are there better books?
>
> thanks a lot and sorry for bugging you
>
> best regards
>
> leonardo
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


i need advice

2013-03-24 Thread leonardo selmi
dear python programmers,

i am focused on learning to program but i need help from all of you. i am a 
beginner but it is hard to find the right book or website to learn, i know that 
i have to do exercises but so far i found resources with gaps. i would be very 
grateful if you could give me suggestions. for example i have "think python" 
and "learning python the hard way", do you recommend them or are there better 
books?

thanks a lot and sorry for bugging you

best regards

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


Re: Separate Rows in reader

2013-03-24 Thread Tim Chase
On 2013-03-24 08:57, rusi wrote:
> On Mar 24, 6:49 pm, Tim Chase  wrote:
> After doing:
> 
> >>> import csv
> >>> original = file('friends.csv', 'rU')
> >>> reader = csv.reader(original, delimiter='\t')
> 
> 
> Stripping of the first line is:
> >>> list(reader)[1:]
> >>> [tuple(row) for row in list(reader)[1:]]
> >>> map(tuple,list(reader)[1:])

This works for small sources, but slurps all the data into memory.
Because csv.reader is an iterator/generator, it can process huge CSV
files that wouldn't otherwise fit in memory.  By using either
r.next() (or "next(r)" in newer versions), it fetches one record from
the generator, to be discarded/stored as appropriate.


> Then you can of course make your code more performant thus:
> >>> reader.next()
> >>> (tuple(row) for row in reader)
> 
> In the majority of cases this optimization is not worth it

If the CSV file is large, using the iterator version is usually worth
the small performance penalty, as you don't have to keep the whole
file in memory.  As somebody who regularly deals with 0.5-1GB CSV
files from cellular providers, I speak from experience of having my
machine choke when reading the whole thing in.

> In any case, strewing prints all over the code is a bad habit
> (except for debugging).

Sorry if my print-statements were misinterpreted--I meant them as a
"do what you want with the data here" stand-in (thus the ellipsis).

-tkc



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


Re: Required arguments in argparse: at least one of a group

2013-03-24 Thread Marco

On 03/23/2013 05:27 PM, Rob Day wrote:


I don't know about argparse, but if you use docopt
(http://docopt.org/) then this is easy to do with something like:

"""Usage:

finder.py --file  --dir 
finder.py --pattern  --dir 
finder.py --file  --pattern  --dir 
"""


Thanks Rob, but I was looking for a solution in the stdlib

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


Re: Required arguments in argparse: at least one of a group

2013-03-24 Thread rurpy
On 03/23/2013 10:04 AM, Marco wrote:
> Is there the possibility using the argparse module to group two or more 
> arguments in order to have at least one of them required? For instance, 
> I would like to have not an error only in the following cases:
> 
>python finder.py --file myfile --dir mydir
>python finder.py --pattern mypattern --dir mydir
>python finder.py --file myfile --pattern mypattern --dir mydir
> 
> where --dir is required, and --file _or_ --parser have to be specified. 
> In other words, I want the parser prints an error message just in this case:
> 
>python finder.py --dir mydir

How about something like:

  p = argparse.ArgumentParser (description="...")
  p.add_argument ('--dir', help="A dir (required).", required=True)
  p.add_argument ('--pattern', help="A pattern.  If not given, --file is 
required.")
  p.add_argument ('--file', help="A filename.  If not given, --pattern is 
required.")
  args = p.parse_args()
  if not args.file and not args.pattern:
p.error ('Either --pattern or --file is required.')

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


Re: ImportError: No module named multipli

2013-03-24 Thread yahya Kacem
On Sunday, March 24, 2013 4:35:29 PM UTC+1, yahya Kacem wrote:
> Hi, i have this 2 files:
> 
> 
> 
> file named multipli:
> 
> 
> 
> #!/usr/bin/python3.2
> 
> #-* - coding : utf-8 -*
> 
> def table(nb, max):
> 
>   i = 0
> 
>   while i < max:
> 
> print(i + 1, " * ", nb, "= ", (i + 1) * nb)
> 
> 
> 
> and file naled test:
> 
> 
> 
> #!/usr/bin/python3.2
> 
> # -* - coding : utf-8 -*
> 
> import os
> 
> import sys
> 
> from multipli import table
> 
> table(3, 20)
> 
> os.system("pause")
> 
> 
> 
> when i run this:
> 
> 
> 
> python3 test
> 
> 
> 
> I get this error:
> 
> Traceback (most recent call last):
> 
>   File "test", line 5, in 
> 
> from multipli import table
> 
> ImportError: No module named multipli 
> 
> both files are in the same directory.
> 
> any help thanks in advance.

Hi, after fixing the infinite loop, there was a missing line in my first post 
inside the while loop I accidentally  deleted this line:
i += 1;
Sorry for that.
adding the .py to the file name (the one to import) did fix the problem, thanks 
for the help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named multipli

2013-03-24 Thread yahya Kacem
+Mark Lawrence sorry for that I'm new here and I didn't know about that.
-- 
http://mail.python.org/mailman/listinfo/python-list


import in Python3.3

2013-03-24 Thread Fabian von Romberg
Hi,

I have a package name collections and inside of my package I want to import the 
collections package from the standard library, but there is name conflicts.

How do I import explicitly from the standard library?

Im working on Python3.3

Thanks in advance and regards,
Fabian

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


Re: how does the % work?

2013-03-24 Thread Tim Roberts
leonardo  wrote:
>
>thank you all!

So, what was the problem?
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import in Python3.3

2013-03-24 Thread Steven D'Aprano
On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote:

> Hi,
> 
> I have a package name collections and inside of my package I want to
> import the collections package from the standard library, but there is
> name conflicts.
> 
> How do I import explicitly from the standard library?

You can't. However, you can import explicitly from your package, or 
implicitly by using a relative import.

Starting from Python 2.7, the "import" statement is always absolute. So 
the line:

  import collections

will always find the first *top level* module or package "collections" in 
the python search path. See below for an important proviso.

Inside your package, you can either use an explicit import like this:

  import mypackage.collections as collections

or use a relative import like this:

  from . import collections

Here is a concrete example. I create a package containing five files:

mypackage/
+-- __init__.py
+-- collections.py
+-- absolute_import.py
+-- explicit_import.py
+-- relative_import.py

with the following content:

# absolute_import.py
import collections

# explicit_import.py 
import mypackage.collections as collections

# relative_import.py 
from . import collections


The other two files (collections.py and __init__.py) can be blank. Now, 
from *outside* the package, I can do this:


py> import mypackage.absolute_import
py> import mypackage.explicit_import
py> import mypackage.relative_import
py> 
py> mypackage.absolute_import.collections

py> mypackage.explicit_import.collections

py> mypackage.relative_import.collections



Of course "from mypackage import absolute_import" etc. will also work.


However, beware: if you cd into the package directory, and then launch 
Python, the current directory will contain a file "collections.py" which 
will shadow the standard library collections.py. So don't do that.



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


[RELEASE] Python 2.7.4 release candidate 1

2013-03-24 Thread Benjamin Peterson
I'm happy to announce the first release candidate of 2.7.4.

2.7.4 will be the latest maintenance release in the Python 2.7 series.
It includes hundreds of bugfixes to the core language and standard
library.

There has recently been a lot of discussion about XML-based denial of service
attacks. Specifically, certain XML files can cause XML parsers, including ones
in the Python stdlib, to consume gigabytes of RAM and swamp the CPU. 2.7.4 does
not include any changes in Python XML code to address these issues. Interested
parties should examine the defusedxml package on PyPI:
https://pypi.python.org/pypi/defusedxml

2.7.4 release candidate 1 is a testing release. Deploying it in production is
not recommended. However, please download it and test with your libraries and
applications, reporting any bugs you may find.

Assuming no horrible bugs rear their heads, a final release of 2.7.4 will occur
in 2 weeks.

Downloads are at

http://python.org/download/releases/2.7.4/

As always, please report bugs to

http://bugs.python.org/

Enjoy,
Benjamin Peterson
2.7 Release Manager
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Separate Rows in reader

2013-03-24 Thread Jiewei Huang
On Sunday, March 24, 2013 3:20:29 PM UTC+10, Jiewei Huang wrote:

thanks to you guys i got my desire outcome! i will continue to code on writing 
and saving of csv file 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import in Python3.3

2013-03-24 Thread Fabian von Romberg
Hi Steven,

thanks a lot for the explanation.

I will keep in mind not to use names for my modules that can shadow the 
standard library.

Regards,
Fabian

On 03/24/2013 07:27 PM, Steven D'Aprano wrote:
> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote:
> 
>> Hi,
>>
>> I have a package name collections and inside of my package I want to
>> import the collections package from the standard library, but there is
>> name conflicts.
>>
>> How do I import explicitly from the standard library?
> 
> You can't. However, you can import explicitly from your package, or 
> implicitly by using a relative import.
> 
> Starting from Python 2.7, the "import" statement is always absolute. So 
> the line:
> 
>   import collections
> 
> will always find the first *top level* module or package "collections" in 
> the python search path. See below for an important proviso.
> 
> Inside your package, you can either use an explicit import like this:
> 
>   import mypackage.collections as collections
> 
> or use a relative import like this:
> 
>   from . import collections
> 
> Here is a concrete example. I create a package containing five files:
> 
> mypackage/
> +-- __init__.py
> +-- collections.py
> +-- absolute_import.py
> +-- explicit_import.py
> +-- relative_import.py
> 
> with the following content:
> 
> # absolute_import.py
> import collections
> 
> # explicit_import.py 
> import mypackage.collections as collections
> 
> # relative_import.py 
> from . import collections
> 
> 
> The other two files (collections.py and __init__.py) can be blank. Now, 
> from *outside* the package, I can do this:
> 
> 
> py> import mypackage.absolute_import
> py> import mypackage.explicit_import
> py> import mypackage.relative_import
> py> 
> py> mypackage.absolute_import.collections
> 
> py> mypackage.explicit_import.collections
> 
> py> mypackage.relative_import.collections
> 
> 
> 
> Of course "from mypackage import absolute_import" etc. will also work.
> 
> 
> However, beware: if you cd into the package directory, and then launch 
> Python, the current directory will contain a file "collections.py" which 
> will shadow the standard library collections.py. So don't do that.
> 
> 
> 


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


Re: Separate Rows in reader

2013-03-24 Thread rusi
On Mar 24, 11:28 pm, Tim Chase  wrote:
>
> Sorry if my print-statements were misinterpreted--I meant them as a
> "do what you want with the data here" stand-in (thus the ellipsis).

Heh! I assumed the OP was a noob to whom this was directed (and whose
original had the print statements in loops).

> As somebody who regularly deals with 0.5-1GB CSV
> files from cellular providers, I speak from experience of having my
> machine choke when reading the whole thing in.

If the 'friends.csv' of the OP goes up to 1GB... Now thats gregarious!
-- 
http://mail.python.org/mailman/listinfo/python-list


io.BytesIO

2013-03-24 Thread Fabian von Romberg
Hi,

is there any way to get the allocated memory size from a io.BytesIO object?

Thanks and regards,
Fabian

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


Re: io.BytesIO

2013-03-24 Thread Steven D'Aprano
On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote:

> Hi,
> 
> is there any way to get the allocated memory size from a io.BytesIO
> object?

The same as for any object:

py> import io, sys
py> obj = io.BytesIO()
py> sys.getsizeof(obj)
48


Is this what you are after, the size of the object itself, including any 
overhead?


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


Re: io.BytesIO

2013-03-24 Thread Fabian von Romberg
Hi Steven,


actually why I need is to know how much memory has been allocated for buffering.

getsizeof gets the size of the object structure.

For example, if I do io.BytesIO.truncate(1), it will resize the buffer to 
1 bytes.  So my question is how to get those 1 back from an attribute 
or method?

Regards,
Fabian

On 03/24/2013 11:47 PM, Steven D'Aprano wrote:
> On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote:
> 
>> Hi,
>>
>> is there any way to get the allocated memory size from a io.BytesIO
>> object?
> 
> The same as for any object:
> 
> py> import io, sys
> py> obj = io.BytesIO()
> py> sys.getsizeof(obj)
> 48
> 
> 
> Is this what you are after, the size of the object itself, including any 
> overhead?
> 
> 


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


Re: io.BytesIO

2013-03-24 Thread Steven D'Aprano
On Mon, 25 Mar 2013 00:10:04 -0500, Fabian von Romberg wrote:

> Hi Steven,
> 
> 
> actually why I need is to know how much memory has been allocated for
> buffering.
> 
> getsizeof gets the size of the object structure.

I can see at least four ways to get the current size of the BytesIO 
buffer:

py> obj = io.BytesIO(b"x"*12468)
py> obj.getbuffer().nbytes
12468
py> len(obj.getvalue())
12468
py> len(obj.getbuffer())
12468
py> obj.seek(0, 2)
12468


As far as I can tell, BytesIO objects do not have a fixed size buffer. 
They will increase in size as needed, just like real file objects on a 
disk.



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


Re: Separate Rows in reader

2013-03-24 Thread Jiewei Huang
On Sunday, March 24, 2013 9:10:45 PM UTC+10, ypsun wrote:
> Jiewei Huang於 2013年3月24日星期日UTC+1上午6時20分29秒寫道:
> 
> > Hi all,
> 
> > 
> 
> > 
> 
> > 
> 
> > Currently create a simple text-based database of information about people
> 
> > 
> 
> >  
> 
> > 
> 
> > 
> 
> > 
> 
> > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such:
> 
> > 
> 
> > Name AddressTelephone   Birthday  
> 
> > 
> 
> > John Konon  Ministry of Moon Walks  4567882 27-Feb
> 
> > 
> 
> > Stacy Kisha Ministry of Man Power   1234567 17-Jan
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > My codes are :
> 
> > 
> 
> > import csv
> 
> > 
> 
> > original = file('friends.csv', 'rU')
> 
> > 
> 
> > reader = csv.reader(original)
> 
> > 
> 
> > 
> 
> > 
> 
> > for row in reader:
> 
> > 
> 
> > 
> 
> > 
> 
> > print row
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > and the output is :
> 
> > 
> 
> > ['Name', ' Address', 'Telephone', 'Birthday']
> 
> > 
> 
> > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb']
> 
> > 
> 
> > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan']
> 
> > 
> 
> > 
> 
> > 
> 
> > But i wanted to make it
> 
> > 
> 
> > 
> 
> > 
> 
> > [('John Cleese', 'Ministry of Silly Walks', '421', '27-Feb'),
> 
> > 
> 
> > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
> 
> > 
> 
> > 
> 
> > 
> 
> > can someone show me guidance to this issue
> 
> > 
> 
> > 
> 
> > 
> 
> > Thanks all
> 
> 
> 
> import csv
> 
> original = file('friends.csv', 'rU')
> 
> reader = csv.reader(original)
> 
> print [tuple(row) for row in reader][1:]
> 
> 
> 
> is this you want?
> 
> Note that:
> 
> 1) I assume your csv file content are seperated by comma
> 
> 2) this way allocates your memory, will be a trouble when a big table :P

Hi guys, i got into another situation i was told not to use csv library and 
currently my code is :

f = open('friends.csv', 'rU')
for row in f:

print [row for (row) in f]

output :
['John Cleese,Ministry of Silly Walks,421,27-Oct\n', 'Stacy Kisha,Ministry 
of Man Power,1234567,17-Jan\n']

i need it to become :
[('John Cleese', 'Ministry of Silly Walks', '421', '27-Oct'), ('Stacy 
Kisha', 'Ministry of Man Power', '1234567', '17-Jan')]

guide me please
-- 
http://mail.python.org/mailman/listinfo/python-list