[Tutor] help

2011-10-10 Thread George Nyoro
On 10/10/2011, tutor-requ...@python.org  wrote:
> Send Tutor mailing list submissions to
>   tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
> You can reach the person managing the list at
>   tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. I am trying to print list elements but i am getting 'none'
>   (Praveen Singh)
>2. Re: I am trying to print list elements but i am getting
>   'none' (Nitin Pawar)
>3. Re: I am trying to print list elements but i am getting
>   'none' (Christian Witts)
>4. Re: I am trying to print list elements but i am getting
>   'none' (Steven D'Aprano)
>5. Re: I am trying to print list elements but i am getting
>   'none' (Wayne Werner)
>6. Re: I am trying to print list elements but i am getting
>   'none' (Bod Soutar)
>
>
> --
>
> Message: 1
> Date: Mon, 10 Oct 2011 09:26:31 -0400
> From: Praveen Singh 
> To: tutor@python.org
> Subject: [Tutor] I am trying to print list elements but i am getting
>   'none'
> Message-ID:
>   
> Content-Type: text/plain; charset="iso-8859-1"
>
> This is my code-
>  def getNumbers(num):
> myList=[]
> for numbers in range(0,num,2):
>   print myList.append(numbers)
>
>
> output-
 getNumbers(10)
> None
> None
> None
> None
> None
>
> Then i find out that list.append doesn't return anything.Then what should i
> use for this kind of operation.but if i do something like this on idle's
> interpreter it gives me answer-
 myList=[]
 myList.append(8)
 print myList
> [8]
>
> Confused!!!
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> 
>
> --
>
> Message: 2
> Date: Mon, 10 Oct 2011 19:00:40 +0530
> From: Nitin Pawar 
> To: Praveen Singh 
> Cc: tutor@python.org
> Subject: Re: [Tutor] I am trying to print list elements but i am
>   getting 'none'
> Message-ID:
>   
> Content-Type: text/plain; charset="iso-8859-1"
>
> Try giving the print statement outside the for loop
>
> On Mon, Oct 10, 2011 at 6:56 PM, Praveen Singh
> wrote:
>
>> This is my code-
>>  def getNumbers(num):
>> myList=[]
>> for numbers in range(0,num,2):
>>   print myList.append(numbers)
>>
>>
>> output-
>> >>> getNumbers(10)
>> None
>> None
>> None
>> None
>> None
>>
>> Then i find out that list.append doesn't return anything.Then what should
>> i
>> use for this kind of operation.but if i do something like this on idle's
>> interpreter it gives me answer-
>> >>> myList=[]
>> >>> myList.append(8)
>> >>> print myList
>> [8]
>>
>> Confused!!!
>>
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Nitin Pawar
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> 
>
> --
>
> Message: 3
> Date: Mon, 10 Oct 2011 15:32:28 +0200
> From: Christian Witts 
> To: Praveen Singh 
> Cc: tutor@python.org
> Subject: Re: [Tutor] I am trying to print list elements but i am
>   getting 'none'
> Message-ID: <4e92f3ec.8080...@compuscan.co.za>
> Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
> On 2011/10/10 03:26 PM, Praveen Singh wrote:
>> This is my code-
>>  def getNumbers(num):
>> myList=[]
>> for numbers in range(0,num,2):
>>   print myList.append(numbers)
>>
>>
>> output-
>> >>> getNumbers(10)
>> None
>> None
>> None
>> None
>> None
>>
>> Then i find out that list.append doesn't return anything.Then what
>> should i use for this kind of operation.but if i do something like
>> this on idle's interpreter it gives me answer-
>> >>> myList=[]
>> >>> myList.append(8)
>> >>> print myList
>> [8]
>>
>> Confused!!!
>>
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> If you seperate your print and the myList.append operation you will get
> what you want, which is why it works in IDLE.  Are you sure you don't
> want to rather build your list, and return it from your function and
> then when you call it you do `print getNumbers(10)` if you wish.
>
> --
>
> Christian Witts
> Python Developer
>
> //
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> 

[Tutor] Pyinstaller Database

2011-10-13 Thread George Nyoro
Hi guys:
Im a beginner in coding and wanted to distribute some of my code to
friends on linux distros. Pyinstaller works well enough. Theres a
situation where I use pickle module to save data to an external file.
The file is not a py file and when I use pyinstaller, it does nt
compile the file too. Is there anyway I can make a none *.py file or
use a databse file s that it is compiled too?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pyinstaller Database

2011-10-13 Thread George Nyoro
Hi guys:
Im a beginner in coding and wanted to distribute some of my code to
friends on linux distros. Pyinstaller works well enough. Theres a
situation where I use pickle module to save data to an external file.
The file is not a py file and when I use pyinstaller, it does nt
compile the file too. Is there anyway I can make a none *.py file or
use a databse file s that it is compiled too?

On 13/10/2011, tutor-requ...@python.org  wrote:
> Send Tutor mailing list submissions to
>   tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
> You can reach the person managing the list at
>   tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. Re: problem with using set (delegb...@dudupay.com)
>2. Re: map one file and print it out following the sequence
>   (Dave Angel)
>3. Re: problem with using set (Dave Angel)
>4. Re: problem with using set (Prasad, Ramit)
>
>
> --
>
> Message: 1
> Date: Thu, 13 Oct 2011 15:18:24 +
> From: delegb...@dudupay.com
> To: "tutor@python.org" 
> Subject: Re: [Tutor] problem with using set
> Message-ID:
>   
> <263695032-1318519103-cardhu_decombobulator_blackberry.rim.net-1700908878-@b18.c12.bise7.blackberry>
>   
> Content-Type: text/plain
>
> +1 Ramit.
> Sent from my BlackBerry wireless device from MTN
>
> -Original Message-
> From: "Prasad, Ramit" 
> Sender: tutor-bounces+delegbede=dudupay@python.org
> Date: Thu, 13 Oct 2011 11:09:24
> To: tutor@python.org
> Subject: Re: [Tutor] problem with using set
>
> Approach:-
 a='hello'
 set(a)
> set(['h', 'e', 'l', 'o']), so i am thinking somehow if i remove 'l' and i
> join the string, i will get the desired output.
>
> 2.
 a='microsoft'
 set(a)
> set(['c', 'f', 'i', 'm', 'o', 's', 'r', 't'])
 print ''.join(set(a))
> cfimosrt
>
> When i print "Hello", i get the output as "helo"(in same sequence) but when
> i write "microsoft" i get this-"cfimosrt". So, it means i can't predict the
> outcome of set(a)??
> =
>
> Are you required to use set? If you are not, I think the following will be
> easier.
 'hello'.replace( 'l', '' )
> 'heo'
 'microsoft'.replace( 'o', '' )
> 'micrsft'
>
> If you require set, you can do:
>
 s = set("microsoft")
 s
> set(['c', 'f', 'i', 'm', 'o', 's', 'r', 't'])
 s.remove('o')
 string = []
 for letter in 'microsoft':
> ... if letter in s:
> ... string.append( letter )
> ...
 ''.join( string )
> 'micrsft'
>
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
>
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
> --
>
> Message: 2
> Date: Thu, 13 Oct 2011 11:43:15 -0400
> From: Dave Angel 
> To: lina 
> Cc: tutor@python.org
> Subject: Re: [Tutor] map one file and print it out following the
>   sequence
> Message-ID: <4e970713.6020...@davea.name>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 10/13/2011 09:09 AM, lina wrote:
>> 
>>
>>> I think your final version of sortfile() might look something like:
>>>
>>> def sortfile(infilename=**INFILENAME, outfilename=OUTFILENAME):
>>> infile = open(infilename, "r")
>>> intext = infile.readlines()
>>> outfile = open(OUTFILENAME, "w")
>>> for chainid in CHAINID:
>>> print("chain id = ",chainid)
>>>  sortoneblock(chainid, intext, outfile)
>>> infile.close()
>>> outfile.close()
>>>
>>
>> $ python3 map-to-itp.py
>> {'O4': '2', 'C19': '3', 'C21': '1'}
>> C
>> Traceback (most recent call last):
>>File "map-to-itp.py", line 55, in
>>  sortfile()
>>File "map-to-itp.py", line 17, in sortfile
>>  sortoneblock(chainid,intext,OUTFILENAME)
>>File "map-to-itp.py", line 29, in sortoneblock
>>  f.write(line[1].strip() for line in temp)
>> TypeError: must be str, not generator
>>
>>
>
> When you see an error message that describes a generator, it means you
> usually have a for-expression used as a value.
>
> At your stage of learning you probably be ignoring generators and list
> comprehensi

[Tutor] Interprocess communication

2011-12-06 Thread George Nyoro
Hey guys,
  Really want to thank all of you for helping and bearing with
some of us and the questions we ask around here. I was making a gtk
app sometime ago to copy files from a cd or dvd to my hard disk since
the normal ubuntu copy thing would stop when it encountered some
error, so I needed one that read through errors or none.
   I did in two modules: one having gtk code and the other having the
copy code, then id import the copy code into gtk. The thing is that
when the gtk called the copy module to do so, the process would take
long and so the application would become none responsive. Also, there
was a progress bar that was supposed to get data after the copy module
copied some block so that it displayed amouint copied so far but it
wouldnt display progress, even when it was supposed to do so from the
return value of a function.
 Can anyone show me how to run the gtk and copy code as separate
processes since this seems to be the only way that the application
graphics wont hang? Thanks in advance.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Super In tkinter class inheritance

2011-12-07 Thread George Nyoro
I was observing the tkinter code under the topic "Creating arbitrary
number of destinations. (GUI program)" in the previous email and saw
this super thing:
> class ChooseDestinationWindow(Frame): def __init__(self,master):
>super(ChooseDestinationWindow,self).__init_
_(master)

What exactly does this super method since I have seen it numerous
times before and as far as I can see it is not anything the user
created himself in the class?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Localhost client-server simple ssl socket test program problems

2011-12-15 Thread George Nyoro
>You're trying to connect to the same port on
>localhost as a client and a
>server? I don't know for certain but I don't
>think that should work.
>Two computers?
--
>Alexander

it should work. I did  short tutorial on this like a month ago and it
worked. The only difference is that in mine it didn't have the part
below which is the source of the problem. Also, in mine, I used "send"
and "recv" though I doubt this makes any difference.


> ssl_sock = ssl.wrap_socket(s,
> ca_certs="/home/ckyang/PHA/testsslsocket/
myCA.crt",
> cert_reqs=ssl.CERT_REQUIRED)
> ssl_sock.connect(("127.0.0.1", 1234))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Localhost client-server simple ssl socket test program problems

2011-12-15 Thread George Nyoro
>You're trying to connect to the same port on
>localhost as a client and a
>server? I don't know for certain but I don't
>think that should work.
>Two computers?
--
>Alexander

it should work. I did  short tutorial on this like a month ago and it
worked. The only difference is that in mine it didn't have the part
below which is the source of the problem. Also, in mine, I used "send"
and "recv" though I doubt this makes any difference.


> ssl_sock = ssl.wrap_socket(s,
> ca_certs="/home/ckyang/PHA/testsslsocket/
myCA.crt",
> cert_reqs=ssl.CERT_REQUIRED)
> ssl_sock.connect(("127.0.0.1", 1234))

On 15/12/2011, tutor-requ...@python.org  wrote:
> Send Tutor mailing list submissions to
>   tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
> You can reach the person managing the list at
>   tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. Re: Localhost client-server simple ssl socket test program
>   problems (Alexander)
>2. timeit() help (Robert Sjoblom)
>3. [TUTOR]Code Deciphering (Calle)
>4. Re: [TUTOR]Code Deciphering (Robert Sjoblom)
>5. modify values for object derived from datetime.datetime
>   (rail shafigulin)
>
>
> --
>
> Message: 1
> Date: Thu, 15 Dec 2011 14:24:37 -0500
> From: Alexander 
> To: Yang Chun-Kai 
> Cc: python-l...@python.org, tutor@python.org
> Subject: Re: [Tutor] Localhost client-server simple ssl socket test
>   program problems
> Message-ID:
>   
> Content-Type: text/plain; charset="iso-8859-1"
>
> 2011/12/15 Yang Chun-Kai 
>
>>  Hello,everyone!!
>>
>> I am writing a simple ssl client-server test program on my personal
>> laptop.
>>
>> And I encounter some problems with my simple programs.
>>
>> Please give me some helps.
>>
>> 
>>
>> My server code:
>>
>> import socket
>> import ssl
>> bindsocket = socket.socket()
>> bindsocket.bind(('127.0.0.1', 1234))
>> bindsocket.listen(5)
>> print 'server is waiting for connection...'
>> newsocket, fromaddr = bindsocket.accept()
>> print 'start ssl socket...'
>> connstream = ssl.wrap_socket(newsocket, server_side=True,
>> certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt",
>> keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key",
>> ssl_version=ssl.PROTOCOL_SSLv23)
>> data = connstream.read()
>> print 'connected from address', fromaddr
>> print 'received data as', repr(data)
>> connstream.close()
>>
>> My client code:
>>
>> import socket
>> import ssl
>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>> ssl_sock = ssl.wrap_socket(s,
>> ca_certs="/home/ckyang/PHA/testsslsocket/myCA.crt",
>> cert_reqs=ssl.CERT_REQUIRED)
>> ssl_sock.connect(("127.0.0.1", 1234))
>> ssl_sock.write("hello")
>> ssl_sock.close()
>>
>>
>> ---
>> Server side error:
>>
>> File "views.py", line 17, in & lt;module>
>> connstream = ssl.wrap_socket(newsocket, server_side=True,
>> certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt",
>> keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key",
>> ssl_version=ssl.PROTOCOL_SSLv23)
>>   File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket
>> ciphers=ciphers)
>>   File "/usr/lib/python2.7/ssl.py", line 119, in __init__
>> ciphers)
>> ssl.SSLError: [Errno 336265218] _ssl.c:347: error:140B0002:SSL
>> routines:SSL_CTX_use_PrivateKey_file:system lib
>>
>> Client side error:
>>
>> File "client.py", line 10, in 
>> ssl_sock.connect(("127.0.0.1", 1234))
>>   File "/usr/lib/python2.7/ssl.py", line 299, in connect**
>> self.do_handshake()
>>   File "/usr/lib/python2.7/ssl.py", line 283, in do_handshake
>> self._sslobj.do_handshake()
>> socket.error: [Errno 104] Connection reset by peer
>>
>>
>> 
>> So what is wrong with my code?
>>
>> The codes are so simple and so much like python official site sample
>> demonstration, but I still cant get it work, so frustrating.
>>
>> Seems the problem happened on server side then cause client side cant
>> connect well, is that right?
>>
>> **
>> My platform is ubuntu, with openssl 0.9.8 and python 2.7.
>>
>> All certificates and keys self-signed by openssl for test convenience.
>>
>> This is the site for referrence :
>> http://andyjeffries.co.uk/articles/x509-encrypted-authenticated-socket-ruby-client
>>
>> Or sh

Re: [Tutor] Tutor Digest, Vol 95, Issue 53

2012-01-21 Thread George Nyoro
Hey guys,
I've been making an application and have made a delete method where the
user can delete the instance of that application. e.g. if I have a table
object, I need to be able to delete that instance from within the class and
then it becomes accessible.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Deleting an object

2012-01-29 Thread George Nyoro
Hi all,

   Last time I tried to post a question regarding this, I was asked to
clarify. Okay so here it is. There is a class called Table and objects are
just tables, you know, matrices, holding different types of data. Thing is,
I want to provide a method where one can delete the object and then if the
user tries using a variable to access a certain method or attributes, he
gets an error. Let me give an example;

class Table:

def delete_this(self):

#code to delete this object or assign it null or None

pass

def do_something(self):

pass

x=Table()

x.delete_this()

#at this point, I want such that if I try to use x I get some sort of error
e.g.

x.do_something()

#Error: x is definitely not an object anymore


 All clear?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Sort

2012-01-30 Thread George Nyoro
Hey all, again:
Thanks for the delete thing. Helped with that problem a lot. Especially the
getattr thing came in handy.

Question 1:
How do you guys indent and put in the triple greater than signs and all
that when sending mail? Manually? Coz the last mail I sent was using the
gmail indent thing and it doesnt seem to have worked. Anyway:

Question 2:
I have this script that downloaded a lot of files from one server into one
local directory and the files are named in a particular order and I want
them to be opened in this very same order so that I can copy the contents
of each to one main file and then convert to pdf. However, the naming
schema is like this (Roman numerals in parts) and python doesn't seem to be
able to sort it properly.
1.I.1; 1.I.2; ; 1.I.20;
1.II.1.1;1.II.1.2
1.II.2;...1.II.10; 2.I.3;
Because of the roman numerals that are always in the second part fo the
filename, it could sort based on how I wanted.

I listed all the files in the said directory:
files=os.listdir(location)

I tried using a sort algorithm that goes through the list starting from
index 0 and then compares each index with the next one and if they are not
arranged as they should be, the two are switched and then it starts again.
The thing is, it is so slow! It hardly goes past index three in the list
and there are so many files. *about fifty*.

Could anyone help me with the python impelentation of such an algorith and
how it should sort. Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor