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 <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 +0000 > From: delegb...@dudupay.com > To: "tutor@python.org" <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" <ramit.pra...@jpmorgan.com> > Sender: tutor-bounces+delegbede=dudupay....@python.org > Date: Thu, 13 Oct 2011 11:09:24 > To: tutor@python.org<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 <d...@davea.name> > To: lina <lina.lastn...@gmail.com> > 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: >> <snip> >> >>> 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<module> >> 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 > comprehensions, and just write simple for loops. So you should replace > the f.write with a loop. > > > for item in temp: > f.write(something + "\n") > > One advantage is that you can easily stuff print() functions into the > loop, to debug what's really happening. After you're sure it's right, > it might be appropriate to use either a generator or a list comprehension. > >> I don't know how to fix the writing issue. >> >> can I write the different chainID one into the same OUTFILE? >> >> Thanks, I attached the code I used below: >> >> #!/usr/bin/python3 >> >> import os.path >> >> LINESTOSKIP=0 >> CHAINID="CDEFGHI" >> INFILENAME="pdbone.pdb" >> OUTFILENAME="sortedone.pdb" >> DICTIONARYFILE="itpone.itp" >> mapping={} >> valuefromdict={} >> >> def sortfile(): >> intext=fetchonefiledata(INFILENAME) >> for chainid in CHAINID: >> print(chainid) >> sortoneblock(chainid,intext,OUTFILENAME) >> > One way to get all the output into one file is to create the file in > sortfile(), and pass the file object. Look again at what I suggested > for sortfile(). If you can open the file once, here, you won't have the > overhead of constantly opening the same file that nobody closed, and > you'll have the side benefit that the old contents of the file will be > overwritten. > > Andreas' suggestion of using append would make more sense if you wanted > the output to accumulate over multiple runs of the program. If you > don't want the output file to be the history of all the runs, then > you'll need to do one open(name, "w"), probably in sortfile(), and then > you might as well pass the file object as I suggested. > > >> >> >> def sortoneblock(cID,TEXT,OUTFILE): > > If you followed my suggestions for sortfile(), then the last paramter to > this function would be outfile., and you could use outfile.write(). > As Andreas says, don't use uppercase for non-constants. > >> temp = [] > > #this writes the cID to the output file, once per cID > outfile.write(cID + "\n") > >> for line in TEXT: >> blocks=line.strip().split() >> if len(blocks)== 11 and blocks[3] == "CUR" and blocks[4] == cID >> and >> blocks[2] in mapping.keys(): > > if (len(blocks)== 11 and blocks[3] == "CUR" > and blocks[4] == cID and blocks[2] in mapping ): > > Having the .keys() in that test is redundant and slows execution down > quite a bit. "in" already knows how to look things up efficiently in a > dictionary, so there's no use in converting to a slow list before doing > the slow lookup. > Also, if you put parentheses around the whole if clause, you can span it > across multiple lines without doing anything special. > > >> temp.append((mapping[blocks[2]],line)) >> temp.sort() >> with open(OUTFILE,"w") as f: >> f.write(line[1].strip() for line in temp) >> > See comment above for splitting this write into a loop. You also are > going to have to decide what to write, as you have tuple containing both > an index number and a string in each item of temp. Probably you want to > write the second item of the tuple. Combining these changes, you > would have > for index, line in temp: > outfile.write(line + "\n") > > Note that the following are equivalent: > for item in temp: > index, line = item > outfile.write(line + "\n") > > for item in temp: > outfile.write(item[1] + "\n") > > But I like the first form, since it makes it clear what's been stored in > temp. That sort of thing is important if you ever change it. >> >> >> >> def generatedictionary(dictfilename): >> text=fetchonefiledata(DICTIONARYFILE) >> for line in text: >> parts=line.strip().split() >> if len(parts)==8: >> mapping[parts[4]]=parts[0] >> print(mapping) >> >> >> >> def fetchonefiledata(infilename): >> text=open(infilename).readlines() >> if os.path.splitext(infilename)[1]==".itp": >> return text >> if os.path.splitext(infilename)[1]==".pdb": >> return text[LINESTOSKIP:] >> infilename.close() >> >> >> if __name__=="__main__": >> generatedictionary(DICTIONARYFILE) >> sortfile() >> > > Final note: write() doesn't automatically append a newline, so I tend to > add an explicit one in the write() itself. But if you start seeing > double spacing, that's presumably because the line already had a newline > in it. You could use rstrip() on it (my choice), or remove the + "\n" > in the write() method. > > -- > > DaveA > > > ------------------------------ > > Message: 3 > Date: Thu, 13 Oct 2011 12:43:54 -0400 > From: Dave Angel <d...@davea.name> > To: Praveen Singh <c2praveen30...@gmail.com> > Cc: tutor@python.org > Subject: Re: [Tutor] problem with using set > Message-ID: <4e97154a.2070...@davea.name> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 10/13/2011 10:44 AM, Praveen Singh wrote: >> <SNIP> >> >> 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)?? >> > The set() function converts its input into a set. A set is not ordered > in the usual way, but in such a way as to rapidly find whether a > particular item exists already in the set, and insert it if not. > Inserting a new item might totally rearrange the existing ones, set > doesn't promise anything at all about the order. (Dictionaries are > similar, but while set has only a key, dict has both key and value) > > A set has no value to the assignment as stated. Stick to lists. > > > -- > > DaveA > > > > ------------------------------ > > Message: 4 > Date: Thu, 13 Oct 2011 13:31:53 -0400 > From: "Prasad, Ramit" <ramit.pra...@jpmorgan.com> > To: "tutor@python.org" <tutor@python.org> > Subject: Re: [Tutor] problem with using set > Message-ID: > > <0604e20b5f6f2f4784c9c8c71c5dd4dd2f2165e...@emarc112vs01.exchad.jpmchase.net> > > Content-Type: text/plain; charset="us-ascii" > > ----Original Message----- > From: tutor-bounces+ramit.prasad=jpmorgan....@python.org > [mailto:tutor-bounces+ramit.prasad=jpmorgan....@python.org] On Behalf Of > Prasad, Ramit > Sent: Thursday, October 13, 2011 10:09 AM > 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' > ============================================== > After further thought, I think you might want to keep one of each character > and not remove them all. If so, see below. > > >>>> string = 'microsoft' >>>> dct = {} >>>> for letter in string: > ... dct[ letter ] = string.count( letter ) > ... >>>> for letter, count in dct.iteritems(): > ... reversed_string = string[::-1] # reverse string to leave first > occurrence > ... reversed_string = reversed_string.replace( letter, '', count-1 ) > ... string = reversed_string[::-1] # return it to normal > ... >>>> string > 'microsft' > > If you do not care which duplicate character is left you can skip the lines > with [::-1] and it will leave the last one in the string. > > > 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 > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 92, Issue 67 > ************************************* > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor