Re: [Tutor] Fwd: Newbie trying to get pip run on windows 7
On Tue, Apr 19, 2016 at 11:26 PM, Gustavo Davis via Tutorwrote: > But for some reason after I made the changes and saved them they wont > run. I mean once I go to the file and right click on them and click run > the cmd prompt pops up for a moment and then it just closes down and the > pip module never runs in python. When you run a .py script from Explorer, Windows creates a new console for the script's standard input and output, but this console closes as soon as the script exits (i.e. when the python.exe process exits). Instead you can run the script from an existing cmd shell to inherit the shell's console. > ;C:\Python34\Scripts\pip There's no "Scripts\pip" directory. Only add fully qualified directories to PATH, separated by a semicolon, without quotes, and with no spaces between entries. You can reference another environment variable in PATH, but only if the variable doesn't reference other environment variables. Add ;.PY to PATHEXT to allow running "command" instead of "command.py". > >>> import pyperclip > Traceback (most recent call last): > File " ", line 1, in > import pyperclip > ImportError: No module named 'pyperclip' With PATH set up correctly, you can install this module from a cmd shell using "pip install pyperclip". pip searches for packages on pypi.python.org. This should work fine for pure-Python packages and those with a WHL or EGG that's built for your version of Python. Some source-only packages require building extension modules. If your system isn't configured to build extensions, look for an unofficial WHL on Christoph Gohlke's site: http://www.lfd.uci.edu/~gohlke/pythonlibs ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] R: Tutor Digest, Vol 146, Issue 23
Thanks so much!! Now I try to understand. Once I have did the matrix at absence on presence I want to subtitute the values of 1 or 0 inside the table extract some values form dictionary called tutto. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] R:reformatting data and traspose dictionary
jarod_v6--- via Tutor wrote: > Dear All, > sorry for my not good presentation of the code. > > I read a txt file and I prepare a ditionary > > files = os.listdir(".") > tutto={} > annotatemerge = {} > for i in files: By the way `i` is the one of the worst choices to denote a filename, only to be beaten by `this_is_not_a_filename` ;) > with open(i,"r") as f: > for it in f: > lines = it.rstrip("\n").split("\t") > > if len(lines) >2 and lines[0] != '#CHROM': > > conte = [lines[0],lines[1],lines[3],lines[4]] > > > tutto.setdefault(i+"::"+"-".join(conte)+"::"+str(lines),[]).append(1) > annotatemerge.setdefault("-".join(conte),set()).add(i) > > > > I create two dictionary one > > annotatemerge with use as key some coordinate ( chr3-195710967-C-CG) and > connect with a set container with the name of file names > 'chr3-195710967-C-CG': {'M8.vcf'}, > 'chr17-29550645-T-C': {'M8.vcf'}, > 'chr7-140434541-G-A': {'M8.vcf'}, > 'chr14-62211578-CGTGT-C': {'M8.vcf', 'R76.vcf'}, > 'chr3-197346770-GA-G': {'M8.vcf', 'R76.vcf'}, > 'chr17-29683975-C-T': {'M8.vcf'}, > 'chr13-48955585-T-A': {'R76.vcf'}, > > the other dictionary report more information with as key a list of > separated > using this symbol "::" > > > {["M8.vcf::chr17-29665680-A-G::['chr17', '29665680', '.', 'A', 'G', > {['70.00', > 'PASS', 'DP=647;TI=NM_001042492,NM_000267;GI=NF1,NF1;FC=Silent,Silent', > 'GT:GQ: AD:VF:NL:SB:GQX', '0/1:70:623,24:0. > 0371:20:-38.2744:70']": [1],...} > > > What I want to obtaine is a list whith this format: > > coordinate\tM8.vcf\tR76.vcf\n > chr3-195710967-C-CG\t1\t0\n > chr17-29550645-T-C\t1\t0\n > chr3-197346770-GA-G\t\1\t1\n > chr13-48955585-T-A\t0\t1\n > > > When I have that file I want to traspose that table so have the coordinate > on columns and names of samples on rows (1) Here's a generic way to create a pivot table: def add(x, y): return x + y def pivot( data, get_column, get_row, get_value=lambda item: 1, accu=add, default=0, empty="-/-"): rows = {} columnkeys = set() for item in data: rowkey = get_row(item) columnkey = get_column(item) value = get_value(item) column = rows.setdefault(rowkey, {}) column[columnkey] = accu(column.get(columnkey, default), value) columnkeys.add(columnkey) columnkeys = sorted(columnkeys) result = [ [""] + columnkeys ] for rowkey in sorted(rows): row = rows[rowkey] result.append([rowkey] + [row.get(ck, empty) for ck in columnkeys]) return result if __name__ == "__main__": import csv import sys from operator import itemgetter data = [ ("alpha", "one"), ("beta", "two"), ("gamma", "three"), ("alpha", "one"), ("gamma", "one"), ] csv.writer(sys.stdout, delimiter="\t").writerows( pivot( data, itemgetter(0), itemgetter(1))) print("") csv.writer(sys.stdout, delimiter="\t").writerows( pivot( data, itemgetter(1), itemgetter(0))) As you can see when you run the above code transposing the table is done by swapping the get_column() and get_row() arguments. Instead of the sample data you can feed it something like # Untested. This is basically a copy of the code you posted wrapped into a # generator. I used csv.reader() instead of splitting the lines manually. import csv def gen_data(): for filename in os.listdir(): with open(filename, "r") as f: for fields in csv.reader(f, delimiter="\t"): if len(fields) > 2 and fields[0] != '#CHROM': conte = "-".join( [fields[0], fields[1], fields[3], fields[4]]) yield conte, filename (2) What you want to do with the other dict is still unclear to me. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] R:reformatting data and traspose dictionary
Dear All, sorry for my not good presentation of the code. I read a txt file and I prepare a ditionary files = os.listdir(".") tutto={} annotatemerge = {} for i in files: with open(i,"r") as f: for it in f: lines = it.rstrip("\n").split("\t") if len(lines) >2 and lines[0] != '#CHROM': conte = [lines[0],lines[1],lines[3],lines[4]] tutto.setdefault(i+"::"+"-".join(conte)+"::"+str(lines),[]).append(1) annotatemerge.setdefault("-".join(conte),set()).add(i) I create two dictionary one annotatemerge with use as key some coordinate ( chr3-195710967-C-CG) and connect with a set container with the name of file names 'chr3-195710967-C-CG': {'M8.vcf'}, 'chr17-29550645-T-C': {'M8.vcf'}, 'chr7-140434541-G-A': {'M8.vcf'}, 'chr14-62211578-CGTGT-C': {'M8.vcf', 'R76.vcf'}, 'chr3-197346770-GA-G': {'M8.vcf', 'R76.vcf'}, 'chr17-29683975-C-T': {'M8.vcf'}, 'chr13-48955585-T-A': {'R76.vcf'}, the other dictionary report more information with as key a list of separated using this symbol "::" {["M8.vcf::chr17-29665680-A-G::['chr17', '29665680', '.', 'A', 'G', '70.00', 'PASS', 'DP=647;TI=NM_001042492,NM_000267;GI=NF1,NF1;FC=Silent,Silent', 'GT:GQ: AD:VF:NL:SB:GQX', '0/1:70:623,24:0. 0371:20:-38.2744:70']": [1],...} What I want to obtaine is a list whith this format: coordinate\tM8.vcf\tR76.vcf\n chr3-195710967-C-CG\t1\t0\n chr17-29550645-T-C\t1\t0\n chr3-197346770-GA-G\t\1\t1\n chr13-48955585-T-A\t0\t1\n When I have that file I want to traspose that table so have the coordinate on columns and names of samples on rows ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reformatting data and traspose dictionary
On Wed, Apr 20, 2016 at 01:18:22PM +0200, jarod_v6--- via Tutor wrote: > Hi!!! > I have this problems > I have a dictionary like this: > > [Name_file ::position] = lines That doesn't look like Python syntax. What programming language is it from? > #Samplename::chr10-43606756-C-T::['chr10', '43606756', '.', 'C', 'T', > #'100.00', 'PASS', > #'DP=439;TI=NM_020630,NM_020975;GI=RET,RET;FC=Synonymous_V455V,Synonymous_V455V;EXON', > > #'GT:GQ:AD:VF:NL:SB:GQX', '0/1:100:387,52:0.1185:20:-100.:100'] I don't know what this means. It appears to be all comments starting with #. > And I want to obtain this tables > > Name_file on the row and position on the columns and the one parametr inside > of lines > > ie. > chr10-43606756-C-T... > Samplename,Synonymous_V455V I don't understand what this means either. Remember, we cannot see your input data, and we don't know what output data you want. Can you please show a *simplified* version? There is no need to use the full complexity of your actual data. And please explain what your input data is or where is comes from. For example: "I am reading data from a CSV file..." "I am reading data from a text file..." "I have a string..." "I have a list of strings..." and then show a *simplified* example: data = "X:: ['a', 'b', 'c']" and then show how you want that data to be processed: output = {'a': 1, 'b': 2, 'c': 3} # the part is ignored or whatever it is that you actually want. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reformatting data and traspose dictionary
jarod_v6--- via Tutor wrote: > Hi!!! > I have this problems > I have a dictionary like this: > > [Name_file ::position] = lines > > #Samplename::chr10-43606756-C-T::['chr10', '43606756', '.', 'C', 'T', > #'100.00', 'PASS', > #'DP=439;TI=NM_020630,NM_020975;GI=RET,RET;FC=Synonymous_V455V,Synonymous_V455V;EXON', > #'GT:GQ:AD:VF:NL:SB:GQX', '0/1:100:387,52:0.1185:20:-100.:100'] > > And I want to obtain this tables > > Name_file on the row and position on the columns and the one parametr > inside of lines > > > ie. > chr10-43606756-C-T... > Samplename,Synonymous_V455V > > > > and then I wan to do the traspose of this matrix. > What is the simple way to do this? I'm sorry, I am pretty sure "this" would be easy to achieve if I had the slightest idea what you are trying to do. Please try to express your problem clearly and provide an unambiguous example with text input and the desired data structures to be built from that input. Thank you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] reformatting data and traspose dictionary
Hi!!! I have this problems I have a dictionary like this: [Name_file ::position] = lines #Samplename::chr10-43606756-C-T::['chr10', '43606756', '.', 'C', 'T', '100.00', 'PASS', 'DP=439;TI=NM_020630,NM_020975;GI=RET,RET;FC=Synonymous_V455V,Synonymous_V455V;EXON', 'GT:GQ:AD:VF:NL:SB:GQX', '0/1:100:387,52:0.1185:20:-100.:100'] And I want to obtain this tables Name_file on the row and position on the columns and the one parametr inside of lines ie. chr10-43606756-C-T... Samplename,Synonymous_V455V and then I wan to do the traspose of this matrix. What is the simple way to do this? Thanks so much!! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: List of tuples
On 20/04/16 06:52, isaac tetteh wrote: >> Thanks things are working good now. The only problem is >> i want to print the for loop output on one line instead of on each line. >> Example [1,2,3,4,5] >> Output >> 1 2 3 4 5 >> I would to do this in Jinja I don;t know what Jinja is but... When you say 'print', where do you want to print it? It seems you are using Flask so presumably the output goes to a web page? So presumably you really want to output a string? Or do you literally want to print to the console? If you want a string from a list of values you can use join(): s = ' '.join([str(n) for n in outputList]) If you want to print to console you can use for n in outputList: print n, # note the comma in Python v2 or for n in outputList: print (n, end=' ')) in Python v3 or just combine the techniques: s = ' '.join([str(n) for n in outputList]) print(s) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List of tuples
On 19/04/16 21:56, isaac tetteh wrote: > I have a list like this > [ > ("name",2344,34, "boy"),("another",345,47,"boy", "last") > ] Assuming this is list_tuple... > for row in list_tuple: > for row2 in row: > return row This can't work because return needs to be inside a function. So you obviously are not showing us all of your code. Also the code above would not give the error you report. So we need to see the whole code and the whole error message. Also can you explain how you want the output presented. Do you want values returned from a function or do you want them printed on screen or do you want them represented by a string? Your mail suggests you wanted them printed but your code suggests you want them returned from a function. Which is it? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: List of tuples
> From: isaac tetteh> Date: April 19, 2016 at 9:05:04 PM CDT > To: Danny Yoo > Subject: Re: [Tutor] List of tuples > > Thanks things are working good now. The only problem is i want to print the > for loop output on one line instead of on each line. > Example [1,2,3,4,5] > Output > 1 2 3 4 5 > I would to do this in Jinja > > Sent from my iPhone > >> On Apr 19, 2016, at 8:35 PM, Danny Yoo wrote: >> >> Okay, in the context of a function, the error you're seeing makes more sense. >> >> You need to ensure that the return value of the function is of the right >> type. In SingleView, the intended return value appears to be a structured >> response value. >> >> Given that, then any other return statements in the body of the function are >> suspect: return is a statement that will finish a function. >> >> If a function returns a value of a tour that it isn't supposed to, expect >> that to produce very strange error messages. That's essentially what you're >> seeing. >> >> Looking at the construction of the response at the end: >> >> > return render_template("view.html",data=data,formB=formB) >> > >> >> I'm wondering: perhaps you can collect the extracted column and add it as an >> additional value in you're template? >> >> If you have questions, please feel free to ask. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List of tuples
This a flask app that I am connecting to the mysql @app.route("/viewSingle", methods=['POST','GET']) def SingleView(): formB=singleView() data=[] if request.method=="POST": if formB.validate_on_submit: #if request.form['submit']=="View CONTINENT": c,conn = connection() c.execute('''select * from Country''') data = c.fetchall() data=list(data) for row in data: for a in row: return row //this is the problem #return str(data) #data=list(data) c.close () conn.close () #return data return render_template("view.html",data=data,formB=formB) error ValueErrorValueError: too many values to unpackTraceback (most recent call last)File "/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__return self.wsgi_app(environ, start_response)File "/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_appresponse = self.make_response(self.handle_exception(e))File "/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exceptionreraise(exc_type, exc_value, tb)File "/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_appresponse = self.full_dispatch_request()File "/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 1478, in full_dispatch_requestresponse = self.make_response(rv)File "/home/isaac/flasky/project_1/lib/python2.7/site-packages/flask/app.py", line 1563, in make_responserv, status, headers = rv + (None,) * (3 - len(rv))ValueError: too many values to unpack > From: d...@hashcollision.org > Date: Tue, 19 Apr 2016 15:01:41 -0700 > Subject: Re: [Tutor] List of tuples > To: itette...@hotmail.com > CC: tutor@python.org > > On Tue, Apr 19, 2016 at 1:56 PM, isaac tettehwrote: > > I have a list like this > > [ > > ("name",2344,34, "boy"),("another",345,47,"boy", "last") > > ] > > How do u get each value from it like > > Output > > name > > 2344 > > 34 > > ... > > > > What i did was > > for row in list_tuple: > > for row2 in row: > > return row > > > > But i get error too many value to unpack > > > Hi Issac, > > Can you copy and paste the exact error message and stack trace that > you're seeing? Try not to paraphrase it: we need to see exactly the > text is saying. In some cases, we'll even pay attention to whitespace > and other insanely silly details. :P > > Since that's tedious for you to retype, just use copy-and-paste. > Include everything that the error message says, even if it doesn't > make sense to you. We'll try to help you interpret what the error is > saying. Unfortunately, you paraphrased the error message above too > much: I have no good guesses from what you've presented so far. > > Also, try to show the entire program that you ran as well. The > snippet you showed us is incomplete, because we don't know how the > program defines "list_tuple". Generally, you want to include enough > detail when asking for help that it's really easy for the tutors here > to "reproduce" your problem. That way, we can see the same problem > that you see. That's important. > > > My best guess so far, from all that you've shown us, is that a > *different* part of the program is responsible for the error you're > showing us. That's why we need more details: I think something else > other than what you're showing us is producing that error. The reason > I think so is because no part of the program you're showing us is > doing tuple unpacking, at least from what I can tell. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Newbie trying to get pip run on windows 7
-- Forwarded message -- From: Gus DavisDate: Apr 19, 2016 9:53 PM Subject: Newbie trying to get pip run on windows 7 To: webmas...@python.org Cc: From: Gustavo Davis Sent: Tuesday April 19th, 2016 To: Python Org Subject: Python Module issues (specifically pip) Greetings! My name is Gustavo Davis. I am enjoying immensely what I'm learning about Python and all that it has to offer. Keep up the good work with Python and please continue making it one of the most popular and open source programming languages. For right now the only thing that is causing me issues is with getting Pip to run on my PC. I've downloaded the files to my desktop folder and Ive even tried to look up the answers on youtube and other places. Some of the answers I understand about going to start>computer>properties>advancesystemsetttings>environmentvariables>path>edit and then add something like this: ;C:\Python34\Scripts\pip C:\Users\Owner\Desktop\Python Folder\Scripts But for some reason after I made the changes and saved them they wont run. I mean once I go to the file and right click on them and click run the cmd prompt pops up for a moment and then it just closes down and the pip module never runs in python. I have version 3.4.4. and 3.5.1. I'm very new to Python and I have to admit I'm not used to using the cmd prompt to install modules and I'm not sure that I understand how to do that. Any help you can give with this would be greatly appreciated. This problem has me stomped so much I almost wanted to give up for a while on Python. But I still have a love for its goals and its philosophy and that's what continues to draw me to it. I've very new to programming in general and thats why I when I came across Python I wanted to learn it and even work primarily a Python Developer one day. I know that most likely this question that has been addressed on the website. However I just kinda felt frustrated and wanted to speak with someone directly since I don't know much about programming at all. Below in the attachments are some the errors I keep getting even with IDLE. Please have a good day and thank you for taking out the time to listen to me. Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import pip >>> import pyperclip Traceback (most recent call last): File " ", line 1, in import pyperclip ImportError: No module named 'pyperclip' >>> ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor