Re: [Tutor] passing named arguments through command line
Hello, take a look at argparse library. --- import argparse parser = argparse.ArgumentParser(description=My prgoram) parser.add_argument('-y', '--y', help=Y value, required=True) parser.add_argument('-x', '--x', help=X value, required=True) def main(x=1, y=2): print x print y if __name__ == '__main__': args = parser.parse_args() main(x=args.x, y=args.y) Enjoy! Lukas On 10/30/2014 03:01 PM, Robert Sokolewicz wrote: I have a function with optional arguments x, y and I would like to pass y or z using a named variable through the command line. Inside a python script main(y=3) would work, but I have trouble passing y=3 as an argument in command line. I have tried the following: import sys def main(x=1, y=2): print x print y if __name__ == '__main__': main(*sys.argv[1:]) - from my terminal I get: $ python script.py 1 2 $ python script.py y=3 y=3 2 whereas I would like the following to happen: $ python script.py y=3 1 3 Is this doable in any convenient way? thanks in advance! -Robert ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I let the Python Console display more decimal precision?
Hi, from the question you're using python 2.x you can do either: 26.0/12 (float divide by int - it retypes both to floats and gets you 2.) or at the beginning do: from __future__ import division That will activate python3 way of dividing - which gives you 2. Lukas. On 06/12/2014 02:48 AM, Marino David wrote: Hi All: I am a newbie at the Python. I type 26/12 in Python Console and get result of 2. It is obvious that the corresponding result should be 2... I don't know why the Console only returns the integer part of true result. Anyone can help me out? Thanks David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] code review
Post it somewhere on github and I'll try to take a look at it. Lukas On 06/10/2014 05:51 PM, Adam Gold wrote: Hi there. I've been writing a script that is now finished and working (thanks, in part, to some helpful input from this board). What I'd really like to do now is go through it with an 'expert' who can point out ways I may have been able to code more efficiently/effectively. I don't think it would be appropriate to post the whole script here and ask how could I do this better (!) so I was wondering if anyone knows of ways for python noobs to connect with python experts for this sort of exercise. I understand people can be really busy so I'm happy to pay for someone's time if necessary. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python sockets
Hi, fist - are you really triyng to have open 64 000 ports? ok, i suppose you have your reasons, but this is not a good idea - you'll block most applications that use these ports .. The problem is with your main function - you have PORT defined, but it is not global, it is only local, and when you add +1 to it, next spawned process will have PORT with previous value. either use global PORT, or have it as a parameter for the function: main(port): .. PORT = port while startingPort65535: thread.start_new_thread(setup(startingPort)) startingPort=startingPort+1 Lukas On 06/10/2014 01:33 AM, Jon Engle wrote: I am trying to open ports 1025-65535 with the following code (Mostly found online with small modifications). I am unable to bind anything other than the one port which is selected as input. What am I missing and how do I bind all the ports simultaneously? #!/usr/bin/python # This is server.py file from socket import * #import the socket library import thread #import the thread library startingPort=input(\nPlease enter starting port: ) startingPort=int(startingPort) def setup(): ##let's set up some constants HOST = ''#we are the host PORT = startingPort#arbitrary port not currently in use ADDR = (HOST,PORT)#we need a tuple for the address BUFSIZE = 4096#reasonably sized buffer for data ## now we create a new socket object (serv) ## see the python docs for more information on the socket types/flags serv = socket( AF_INET,SOCK_STREAM) ##bind our socket to the address serv.bind((ADDR))#the double parens are to create a tuple with one element serv.listen(5)#5 is the maximum number of queued connections we'll allow serv = socket( AF_INET,SOCK_STREAM) ##bind our socket to the address serv.bind((ADDR))#the double parens are to create a tuple with one element serv.listen(5)#5 is the maximum number of queued connections we'll allow print 'listening...' PORT=PORT+1 conn,addr = serv.accept() #accept the connection print '...connected!' conn.send('TEST') conn.close() while startingPort65535: thread.start_new_thread(setup()) startingPort=startingPort+1 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SHA256 P2P Chat in python
Hi, I did a similar thing recently, a chat, that encrypts and signs (for authenticity) each message sent with private-pub keypair: https://github.com/lunemec/python-chat. It is not p2p, it sends messages to server, which decrypts them, encrypts with its pubkey and sends to all clients for decoding. It is just a prototype and could be done better. I wanted to have the server act only as a relay for clients to discover each other (no need for DHT) and then to forward each client's pubkey to all others. I'm not sure exactly how onion routing would be done, I suppose something similar to Tor, but how would you want to use it on chat? Lukas On 06/08/2014 09:07 AM, Danny Yoo wrote: I was wondering if it is possible to make a p2p chat application with sha256 secured onion routing in python, and if so, what functions, guides, modules, etc. would I have to look at. This is somewhat outside of the experience of many folks on this list; you might consider asking on a broader forum. I suspect it is possible, given that Bram Cohen's original bittorent was written in Python. Try asking on the main Python mailing list. Good luck! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to create a dictionary for ount elements
Hi, I'd suggest using different data structure for the intersect of samples from a program. data = { 'program1': { 'sample1': {'TP53', 'ASD'}, 'sample2': {'ASD'}, }, 'program2': { 'sample1': {'ASD'} } } this way you can do this: for program in data: program_genes = [] for sample, value in data[program].iteritems(): program_genes.append(value) data[program]['intersection'] = set.intersection(*program_genes) Now you have in each 'programX' sub-dictionary key 'intersection', with intersection of all the program genes. Lukas On 06/04/2014 12:29 PM, jarod...@libero.it wrote: Dear all thanks for your suggestion!!! Thanks to your suggestion I create this structure:with open(prova.csv) as p: for i in p: lines =i.rstrip(\n).split(\t) ...: print lines ...: ['programs ', 'sample', 'gene', 'values'] ['program1', 'sample1', 'TP53', '2'] ['program1', 'sample1', 'TP53', '3'] ['program1', 'sample2', 'PRNP', '4'] ['program1', 'sample2', 'ATF3', '3'] ['program2', 'sample1', 'TP53', '2'] ['program2', 'sample1', 'PRNP', '5'] ['program2', 'sample2', 'TRIM32', '4'] ['program2', 'sample2', 'TLK1', '4'] In [4]: with open(prova.csv) as p: for i in p: lines =i.rstrip(\n).split(\t) dizlines diz In [4]: with open(prova.csv) as p: for i in p: lines =i.rstrip(\n).split(\t) line = (lines[0],lines[1]) ...: diz.setdefault(line,set()).add(lines[2]) ...: In [5]: diz Out[5]: {('program1', 'sample1'): {'TP53'}, ('program1', 'sample2'): {'ATF3', 'PRNP'}, ('program2', 'sample1'): {'PRNP', 'TP53'}, ('program2', 'sample2'): {'TLK1', 'TRIM32'}, ('programs ', 'sample'): {'gene'}} So what I want to do is to use intersect between the keys recursively: s = diz[('program2', 'sample1'] : : KeyboardInterrupt In [14]: s = diz[('program2', 'sample1')] In [15]: s Out[15]: {'PRNP', 'TP53'} In [16]: a Out[16]: {'ATF3', 'PRNP'} In [17]: s.inte s.intersection s.intersection_update In [17]: s.intersection(a) Out[17]: {'PRNP'} How can Have a intersect of all my dictionary and from ('program1', 'sample1') vs ('program1', 'sample2')... I want to count how many genes are common Thanks in advance for your help! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string list in alphabetical!
On 10/21/2013 01:16 PM, Steven D'Aprano wrote: On Sun, Oct 20, 2013 at 09:15:05PM -0500, Sammy Cornet wrote: Thank you for help Steven! I intend to correct it. But also I would like to know if I wrote the correctly in order to the output that I'm looking for? I don't know, I didn't study your code in that much detail. Why don't you fix the problems you already know about, then try running it, and see if it works as you expect? That is the normal process of programming: 1) write some code 2) fix the bugs until it will run 3) test if it works correctly 4) repeat until done I'd like to upgrade that process :D ... 1) think about your problem 2) if there are some heplful libraries that can make it way easier, use them 3) write some code 4) fix the bugs until it'll run 5) write unittests 6) test if it works correctly and if unittests pass 7) repeat until done Bye :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] looking for volunteers with testing simple python program
Hello, I changed some simple python client/server chatroom recipe to include RSA keypair based encryption and signature verification because I'm sick of someone spying on my conversations on FB and similar. Here is the code: https://github.com/lunemec/python-chat If anyone is interrested in trying the software - mostly bughunting and improvements please run these commands after downloading the source codes: cd client |openssl genrsa -out your_cert_name.pem -des3 4096 ||openssl rsa -pubout -in yourt_cert_name.pem -passin pass:yourpassword -out your_chatroom_nick.pub ## After this step, please send me your_chatroom_nick.pub file, it should have the same name.pub as you want to use in the chatroom, otherwise we can't decrypt your messages # if you don't have pycrypt, then sudo pip install pycrypto python client.py your_chatroom_nick nemec.lu 3490 your_cert_name.pem yourpassword Now we should be able to chat :) Enjoy, and please don't kill me for writing here :) Lukas | ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] EXE Problem
Do Win+R type: cmd hit enter. in the opened cmd write cd C:/where/you/have/the/exe (you can move it to C: for simplicity) and run it from there it will not close this time, and you can see the debugging info. Enjoy. On 06/19/2013 08:50 AM, Jack Little wrote: I compiled a program in python, but the second I open it, there is a flash of the error, but then the cmd window closes. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor