A package could import/run encrypted python scripts
Hello everyone, I'm glad to announce a python package: pyarmor. PA HREF=http://dashingsoft.com/products/pyarmor.html;Pyarmor 1.7.3/A - A python package could import/run encrypted python scripts. (03-11-14) Some python developer may be not want to distribute the literal python scripts to his customer or other people. So they can use Pyarmor to encrypt python scripts and run/import encrypted python scripts. Pyarmor is published under Shareware license. author: jondy.z...@gmail.com -- Regards Jondy -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Nikola v7.2.0 is out!
On behalf of the Nikola team, I am pleased to announce the immediate availability of Nikola v7.2.0. It features many bugfixes, and also some new useful features. What is Nikola? === Nikola is a static site and blog generator, written in Python. It can use Mako and Jinja2 templates, and input in many popular markup formats, such as reStructuredText and Markdown — and can even turn IPython Notebooks into blog posts! It also supports image galleries, and is multilingual. Nikola is flexible, and page builds are extremely fast, courtesy of doit (which is rebuilding only what has been changed). Find out more at the website: http://getnikola.com/ Downloads = Get it on GitHub and PyPI: https://github.com/getnikola/nikola/releases/tag/v7.2.0 https://pypi.python.org/pypi/Nikola Changes === Features * Added support for fancy dates via moment.js (Issue #1256) * Updates: jQuery v1.11.1, Bootstrap v3.3.0 * Allow presets usage with ``nikola deploy`` — ``DEPLOY_COMMANDS`` is now a dict of {preset: commands} (Issue #1452) * New ``GLOBAL_CONTEXT_FILLER`` setting, functions listed there will be called with the local context and the template name before template rendering. (Issue #1451) * New ``USE_CDN_WARNING`` setting to block warnings about potential ``USE_CDN`` misuse (defaults to True) * ``nikola check -l`` will warn about mixed-security (HTTP on HTTPS) * New ``ConfigPlugin`` category (without any specific behavior by default) * New meta property “previewimage” for use with Open Graph (Issue #1421) * Expose publishing date, tags, and more in Open Graph * XSL Transform RSS into pretty and helpful webpages when opened in browsers (Issue #1411) Bugfixes * Don’t pull by default in ``github_deploy`` (Issue #1464) * disabled hyphenation for paragraphs with inline math (Issue #1461) * Support filters for all tasks (Issue #1459) * Don’t check cache/ in ``nikola check -l`` (Issue #1447) * Fix new_post for pandoc format (Issue #1445) * Fix STORY_INDEX generation (Issue #1444) * Fix bootswatch creation version check (Issue #1441) * Never rebase while pulling in ``github_deploy`` * Handle better ``new_post --format=pandoc`` when pandoc is not defined (Issue #1422) * Open Graph properly uses latest RDFa in HTML – fixes validation * Fix sitemap generation (Issue #1397 via #1032) * Use destination folder names as titles for titleless listings * Fixed problems with installation from .tar.gz under Windows (Issue #1417) * Fixed encoding problems in WordPress urlmap writer (Issue #1416) * Added back atom:link in RSS feeds * Fixed Nikola-based page redirects in Python 2 (Issue #1414) * Fixed files/\*.php (skip post/story-specific filters) (Issue #1403) * Warn about missing / in BASE_URL differently (explicit request to fix the config file) * Fix broken ``auto -b`` option (Issue #1437) -- Chris Warrick http://chriswarrick.com/ PGP: 5EAAEA16 -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Python extension using a C library with one 'hello' function
https://github.com/Veek/Python/tree/master/junk/hello doesn't work. I have: hello.c which contains: int hello(void); hello.h To wrap that up, i have: hello.py - _hello (c extension) - pyhello.c - method py_hello() People using this will do: python3.2 import hello python3.2 hello.hello() It doesn't compile/work. deathstar python setup.py build_ext --inplace running build_ext building '_hello' extension creating build creating build/temp.linux-x86_64-3.2 gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes - D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat - Werror=format-security -fPIC -I/usr/include/python3.2mu -c pyhello.c -o build/temp.linux-x86_64-3.2/pyhello.o pyhello.c:15:6: warning: character constant too long for its type [enabled by default] pyhello.c:15:5: warning: initialization makes pointer from integer without a cast [enabled by default] pyhello.c:15:5: warning: (near initialization for 'hellomethods[0].ml_name') [enabled by default] pyhello.c:15:5: warning: initialization from incompatible pointer type [enabled by default] pyhello.c:15:5: warning: (near initialization for 'hellomethods[0].ml_meth') [enabled by default] pyhello.c:15:5: warning: initialization makes integer from pointer without a cast [enabled by default] pyhello.c:15:5: warning: (near initialization for 'hellomethods[0].ml_flags') [enabled by default] gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-3.2/pyhello.o -o /root/github/junk/hello/_hello.cpython-32mu.so import hello Traceback (most recent call last): File stdin, line 1, in module File hello.py, line 1, in module from _hello import * ImportError: ./_hello.cpython-32mu.so: undefined symbol: hello -- https://mail.python.org/mailman/listinfo/python-list
generating unique variable name via loops
Hi, I want to generate a unique variable name for list using python. list1=... list2=... . . . listx=... where x is a number. You can remember it from saving a file in a directory. If you have already created a new file, save dialog sugget that new file is already exist, do you want to save it as new file (1)? so I want to apply it for list names. Do you any idea about this. -- https://mail.python.org/mailman/listinfo/python-list
Idle on Mac issues
I seem to be stuck with some issues of Idle on macs. The page https://www.python.org/download/mac/tcltk seems to talk only of Tcl/Tk versions 8.5 Macports seem to have at 8.6 https://www.macports.org/ports.php?by=librarysubstr=tcl With a direct download of Tcl/Tk there are some security warnings that prevent it from installing. Using whatever Tcl/Tk comes with python means many things dont work: - The options menu wont open - Various keyboard shortcuts dont work Any suggestions/directions? [Me: A non Mac-er with Mac-ers in my class!] -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
4 Kasım 2014 Salı 13:29:34 UTC+2 tarihinde Fatih Güven yazdı: Editted: Grammar revision. Hi, I want to generate a unique variable name for list using python. list1=... list2=... . . . listx=... where x is a number. You can remember it from saving a file in a directory. If you have already created a new file, save dialog suggest that new file is already exist, do you want to save it as new file (1)? so I want to apply it for list names. Do you have any idea about this. -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
Fatih Güven wrote: I want to generate a unique variable name for list using python. list1=... list2=... . . . listx=... where x is a number. You can remember it from saving a file in a directory. If you have already created a new file, save dialog sugget that new file is already exist, do you want to save it as new file (1)? so I want to apply it for list names. Do you any idea about this. Do you really want to use list1, list2, list3, ... as variable names? You shouldn't. Instead use a dict or a list of lists: list_of_lists = [] list_of_lists.append([1, 2, 3]) list_of_lists.append([a, b, c]) list_of_lists.append([foo, bar, baz]) You can then access the second list with letters = list_of_lists[1] print(letters) ['a', 'b', 'c'] On the other hand if you just want to generate names an easy to understand approach is to increment a global variable every time you invoke the name- generating function: _index = 1 def next_name(): ... global _index ... name = list{}.format(_index) ... _index += 1 ... return name ... next_name() 'list1' next_name() 'list2' next_name() 'list3' -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) -- https://mail.python.org/mailman/listinfo/python-list
Re: Idle on Mac issues
On 2014-11-04 12:43:59 +, Rustom Mody said: I seem to be stuck with some issues of Idle on macs. The page https://www.python.org/download/mac/tcltk seems to talk only of Tcl/Tk versions 8.5 System's 8.5 should be enough, if not there's explicit mention of the ActiveTcl distribution. Macports seem to have at 8.6 https://www.macports.org/ports.php?by=librarysubstr=tcl But that won't likely be used by a binary python installation, unless you're using python from MacPorts as well. Using whatever Tcl/Tk comes with python means many things dont work: - The options menu wont open - Various keyboard shortcuts dont work Any suggestions/directions? [Me: A non Mac-er with Mac-ers in my class!] I'm on 10.10 (happily) running MacPorts, I have system's python 2.7.6 as well as 2.7.8 and 3.4.2 from MacPorts, these two built with Xquartz support. I can start the idle binary provided by all of those, the system's with native GUI, and have working Options menu in all of them. I'd suggest the people having issue to describe their issues here, with details on the system version, python version, the exact command they run and the error they get. -- Andrea-- https://mail.python.org/mailman/listinfo/python-list
Re: Dictionaries with variable default.
Op 03-11-14 om 12:09 schreef Chris Angelico: On Mon, Nov 3, 2014 at 10:04 PM, Antoon Pardon antoon.par...@rece.vub.ac.be wrote: Is it possible to have a default dictionary where the default is dependant on the key? I was hoping something like this might work: m = defaultdict(lambda key: key+1) But it obviously doesn't: m[3] Traceback (most recent call last): File stdin, line 1, in module TypeError: lambda() takes exactly 1 argument (0 given) Yes, but not with the defaultdict. Instead, just implement __missing__: class KeyPlusOne(dict): def __missing__(self, key): return key+1 ChrisA So How should I call this: class ...dict(dict): def __init__(self, fun): self.fun = fun def __missing__(self, key): return self.fun(key) -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
Veek M wrote: Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) Why would you do this? -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
4 Kasım 2014 Salı 15:19:20 UTC+2 tarihinde Veek M yazdı: Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) This is okay but i can't use the method .append for example list1.append(abc) -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
4 Kasım 2014 Salı 15:37:59 UTC+2 tarihinde Peter Otten yazdı: Veek M wrote: Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) Why would you do this? I have a structured and repetitive data. I want to read a .txt file line by line and classified it to call easily. For example employee1 has a name, a salary, shift, age etc. and employee2 and other 101 employee have all of it. Call employee1.name or employee2.salary and assign it to a new variable, something etc. -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
Fatih Güven wrote: This is okay but i can't use the method .append for example list1.append(abc) works for me -- https://mail.python.org/mailman/listinfo/python-list
Re: Dictionaries with variable default.
So How should I call this: class ...dict(dict): def __init__(self, fun): self.fun = fun def __missing__(self, key): return self.fun(key) I don't know how you should, but I tried the following which seems to work class KeyPlusOne( dict ) : def __missing__( self , key ) : return ( 2 * key ) + 1 kp1 = KeyPlusOne() d = { } for n in range( 11 ) : d[ n ] = kp1[ n ] print '\n key : value \n' for key , value in d.iteritems() : print '%2d : %2d' % ( key , value ) -- Stanley C. Kitching Human Being Phoenix, Arizona -- https://mail.python.org/mailman/listinfo/python-list
fill, expand from tkinter.pack() layout manager
Hi I dont really understood how fill and expand works with layout manager tkinter.pack() Example: from tkinter import * root = Tk() w = Label(root, text=Red, bg=red, fg=white) w.pack(side=LEFT, fill = BOTH) Here is the result: http://cjoint.com/?0Kepj1E3Tv3 Why is the label w only extended vertically and not horizontally too ? I specified fill = BOTH so it should extend in both direction. (I know that with expand = 1, it will expand in both direction) thx -- https://mail.python.org/mailman/listinfo/python-list
Re: fill, expand from tkinter.pack() layout manager
ast nom...@invalid.com a écrit dans le message de news:5458dfc6$0$27505$426a7...@news.free.fr... w.pack(side=LEFT, fill = BOTH) Why is the label w only extended vertically and not horizontally too ? with: w.pack(side=TOP, fill = BOTH) it expand horizontally but not vertically with: w.pack(side=LEFT, fill = BOTH, expand = 1) or w.pack(side=TOP, fill = BOTH, expand = 1) it expand both horizontally and vertically -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
- Original Message - From: Fatih Güven mfthgu...@gmail.com I have a structured and repetitive data. I want to read a .txt file line by line and classified it to call easily. For example employee1 has a name, a salary, shift, age etc. and employee2 and other 101 employee have all of it. Call employee1.name or employee2.salary and assign it to a new variable, something etc. Some python 2.7 pseudo code to give you some leads employes = {} with open('file.txt') as f_: for line in f_: name, age, phone = line.split(',') employes[name] = (age, phone) print employes If your file is a csv format, it could even be easier using the csv module. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: fill, expand from tkinter.pack() layout manager
4 Kasım 2014 Salı 16:16:52 UTC+2 tarihinde ast yazdı: Hi I dont really understood how fill and expand works with layout manager tkinter.pack() Example: from tkinter import * root = Tk() w = Label(root, text=Red, bg=red, fg=white) w.pack(side=LEFT, fill = BOTH) Here is the result: http://cjoint.com/?0Kepj1E3Tv3 Why is the label w only extended vertically and not horizontally too ? I specified fill = BOTH so it should extend in both direction. (I know that with expand = 1, it will expand in both direction) thx Hi, Packing widgets splits frame into equal areas with expand=1. if expand=false, widgets don't touch each other and widgets save their own dimension. -- https://mail.python.org/mailman/listinfo/python-list
simple download manager
I wish to automate the downloading from a particular site which has some ADs and which requires to click on a lot of buttons before the download starts. What library should I use to handle HTTP? Also, I need to support big files ( 1 GB) so the library should hand the data to me chunk by chunk. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
On Tue, Nov 4, 2014 at 8:52 PM, Veek M vek.m1...@gmail.com wrote: https://github.com/Veek/Python/tree/master/junk/hello doesn't work. I have: hello.c which contains: int hello(void); hello.h To wrap that up, i have: hello.py - _hello (c extension) - pyhello.c - method py_hello() People using this will do: python3.2 import hello python3.2 hello.hello() It doesn't compile/work. [details chomped] Have you considered using Cython? It'll likely make your job a LOT easier. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: simple download manager
On Wed, Nov 5, 2014 at 1:53 AM, Kiuhnm gandal...@mail.com wrote: I wish to automate the downloading from a particular site which has some ADs and which requires to click on a lot of buttons before the download starts. What library should I use to handle HTTP? Also, I need to support big files ( 1 GB) so the library should hand the data to me chunk by chunk. You may be violating the site's terms of service, so be aware of what you're doing. This could be a really simple job (just figure out what the last HTTP query is, and replicate that), or it could be insanely complicated (crypto, JavaScript, and/or timestamped URLs could easily be involved). To start off, I would recommend not writing a single like of Python code, but just pulling up Mozilla Firefox with Firebug, or Google Chrome with in-built inspection tools, or some equivalent, and watching the exact queries that go through. Once you figure out what queries are happening, you can figure out how to do them in Python. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
Fatih Güven wrote: 4 Kasım 2014 Salı 15:37:59 UTC+2 tarihinde Peter Otten yazdı: Veek M wrote: Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) Why would you do this? I have a structured and repetitive data. I was actually asking Veek M. I want to read a .txt file line by line and classified it to call easily. For example employee1 has a name, a salary, shift, age etc. and employee2 and other 101 employee have all of it. Call employee1.name or employee2.salary and assign it to a new variable, something etc. I can only repeat my previous advice. Instead of creating variables for employee1, employee2, and so on make a list of employees: $ cat employees.txt Peter,3000 Paul,2000 Mary,1000 $ cat employees.py #!/usr/bin/env python3 import csv class Employee: def __init__(self, name, salary): self.name = name self.salary = salary if __name__ == __main__: employees = [] with open(employees.txt) as f: for row in csv.reader(f): employees.append(Employee(row[0], int(row[1]))) for employee in employees: print(employee.name, -- salary:, employee.salary, doubloons) $ python3 employees.py Peter -- salary: 3000 doubloons Paul -- salary: 2000 doubloons Mary -- salary: 1000 doubloons You wouldn't want to reference Paul as employee2 -- what if the order in the text file changed? Instead you can make a dict that maps name to employee... employees_by_name = {} for employee in employees: name = employee.name if name in employees_by_name: raise ValueError(duplicate name {}.format(name)) employees_by_name[name] = employee and use that dict to look up an employee: while True: name = input(enter a name ) if name == : print(That's all folks) break if name not in employees_by_name: print(unknown name) else: print(Salary:, employees_by_name[name].salary, doubloons) $ python3 employees.py Peter -- salary: 3000 doubloons Paul -- salary: 2000 doubloons Mary -- salary: 1000 doubloons enter a name Peter Salary: 3000 doubloons enter a name Mary Salary: 1000 doubloons enter a name paul unknown name enter a name Paul Salary: 2000 doubloons enter a name That's all folks $ -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
Hi- Questions like this appear so often in various places (mailing lists, forums, sites like Stack Overflow) that I think a very blunt/candid answer is appropriate. This is especially true since there's always someone who responds to the question as-is with some monstrosity of exec() and string formatting, instead of addressing the underlying issue of using the right data structure for what you're trying to accomplish. On 11/04/2014 06:29 AM, Fatih Güven wrote: I want to generate a unique variable name for list using python. list1=... list2=... . . . listx=... where x is a number. *Incorrect.* You do not want to do this. You think you do, but that's presumably because you aren't familiar with common data structures that are available in Python. As Peter Otten said, this is *exactly* the right situation to use a list. You mentioned having structured and repetitive data, wanting to read a .txt file and process each line, and wanting to access each employee's data as appropriate. The general structure of this would be employees = [] with open('employee_data.txt') as f: ... for line in f: ... # parse_line here isn't anything standard or built-in, it's ... # what you would write to transform a line of the data ... # file into whatever object you're interested in with ... # 'name', 'salary', etc. attributes ... employee = parse_line(line) ... employees.append(employee) ... employees[0].salary 15 Your line1 is now employees[0] and so on. Now, you can *easily* answer questions like what's the total salary of all employees? total = 0 for employee in employees: ... total += employee.salary ... total 7502000 (or 'sum(employee.salary for employee in employees)' of course.) MMR... -- https://mail.python.org/mailman/listinfo/python-list
Re: simple download manager
On Tuesday, November 4, 2014 4:00:51 PM UTC+1, Chris Angelico wrote: On Wed, Nov 5, 2014 at 1:53 AM, Kiuhnm gandal...@mail.com wrote: I wish to automate the downloading from a particular site which has some ADs and which requires to click on a lot of buttons before the download starts. What library should I use to handle HTTP? Also, I need to support big files ( 1 GB) so the library should hand the data to me chunk by chunk. You may be violating the site's terms of service, so be aware of what you're doing. This could be a really simple job (just figure out what the last HTTP query is, and replicate that), or it could be insanely complicated (crypto, JavaScript, and/or timestamped URLs could easily be involved). To start off, I would recommend not writing a single like of Python code, but just pulling up Mozilla Firefox with Firebug, or Google Chrome with in-built inspection tools, or some equivalent, and watching the exact queries that go through. Once you figure out what queries are happening, you can figure out how to do them in Python. ChrisA It'll be tricky. I'm sure of that, but if the browser can do it, so can I :) Fortunately, there are no captchas. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
On Tue, 2014-11-04 at 16:22 +0630, Veek M wrote: https://github.com/Veek/Python/tree/master/junk/hello doesn't work. I have: hello.c which contains: int hello(void); hello.h To wrap that up, i have: hello.py - _hello (c extension) - pyhello.c - method py_hello() People using this will do: python3.2 import hello python3.2 hello.hello() It doesn't compile/work. deathstar python setup.py build_ext --inplace running build_ext building '_hello' extension creating build creating build/temp.linux-x86_64-3.2 gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes - D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat - Werror=format-security -fPIC -I/usr/include/python3.2mu -c pyhello.c -o build/temp.linux-x86_64-3.2/pyhello.o pyhello.c:15:6: warning: character constant too long for its type [enabled by default] pyhello.c:15:5: warning: initialization makes pointer from integer without a cast [enabled by default] pyhello.c:15:5: warning: (near initialization for 'hellomethods[0].ml_name') [enabled by default] pyhello.c:15:5: warning: initialization from incompatible pointer type [enabled by default] pyhello.c:15:5: warning: (near initialization for 'hellomethods[0].ml_meth') [enabled by default] pyhello.c:15:5: warning: initialization makes integer from pointer without a cast [enabled by default] pyhello.c:15:5: warning: (near initialization for 'hellomethods[0].ml_flags') [enabled by default] gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-3.2/pyhello.o -o /root/github/junk/hello/_hello.cpython-32mu.so import hello Traceback (most recent call last): File stdin, line 1, in module File hello.py, line 1, in module from _hello import * ImportError: ./_hello.cpython-32mu.so: undefined symbol: hello When I try your code, I get the error: ImportError: dynamic module does not define init function (PyInit__hello) There were a couple other problems as well. Like 'hello' in hellomethods instead of hello (note the double quotes). Also, NULL is no longer acceptable as a METH_XXXARGS replacement, you need to set it to METH_NOARGS (or MET_VARARGS if you plan on accepting arguments). I've found that you also need a NULL sentinel in the hellomethods array to avoid segfaults on my Linux box. After fixing these problems, you still need to add hello.c to the list of sources in setup.py to make sure that module is built. I've submitted a PR to your github repo showing you the changes necessary to get your module working on my computer. Hope this helps, Jason -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
I'm not sure if it fits your needs, but we are very happy with calling c libs directly from python using ctypes: https://docs.python.org/2/library/ctypes.html It requires a few extra lines in Python to handle the parameter and return types. import ctypes result = ctypes.windll.Hello.hello() -- https://mail.python.org/mailman/listinfo/python-list
Code review
I was wondering if I could get some feedback on the biggest thing I have done as an amateur Python coder. The sidepots algorithm isn't correct yet, but I haven't worked on it in a while and thought I would get some advice before diving back in. import random, os ## class Table(object): def __init__(self,bigblind=20,PLAYERNUM=0,pot=0,PLAYERORDER=None, hand_done=0,\ left_to_act=None,cost_to_play=0,in_hand=None,last_raise=0,cards_in_play=None,round='preflop'): if cards_in_play is None: cards_in_play = [] if in_hand is None: in_hand = [] if PLAYERORDER is None: PLAYERORDER = [] if left_to_act is None: left_to_act = [] self.hand_done = hand_done self.round = round self.cards_in_play = cards_in_play self.last_raise = last_raise self.in_hand = in_hand self.cost_to_play = cost_to_play self.left_to_act = left_to_act self.PLAYERORDER = PLAYERORDER self.bigblind = bigblind self.PLAYERNUM = PLAYERNUM self.pot = pot ## def fillseats(self,listofplayers, playas): seating = [x for x in range(1,len(listofplayers)+1)] random.shuffle(seating) for y in listofplayers: playas[y].seatnumber = seating.pop() for x in listofplayers: newx = str(playas[x].seatnumber)+x self.PLAYERORDER.append(newx) self.PLAYERORDER = sorted(self.PLAYERORDER) neworder = [] for x in self.PLAYERORDER: neworder.append(x[1:]) self.PLAYERORDER = neworder self.PLAYERNUM = len(self.PLAYERORDER) ## def postblinds(self,playas,bigblind,deck): # establish player.start_stack for sidepots for player in self.PLAYERORDER: playas[player].start_stack = playas[player].stacksize # Heads up post blinds if len(self.PLAYERORDER) == 2: if bigblind = playas[self.PLAYERORDER[1]].stacksize: if bigblind == playas[self.PLAYERORDER[1]].stacksize: playas[self.PLAYERORDER[1]].stacksize = 0 self.pot += bigblind playas[self.PLAYERORDER[1]].all_in = 1 playas[self.PLAYERORDER[1]].in_front = bigblind playas[self.PLAYERORDER[1]].put_in_pot = bigblind else: self.pot += playas[self.PLAYERORDER[1]].stacksize playas[self.PLAYERORDER[1]].in_front = playas[self.PLAYERORDER[1]].stacksize playas[self.PLAYERORDER[1]].put_in_pot = playas[self.PLAYERORDER[1]].stacksize playas[self.PLAYERORDER[1]].stacksize = 0 playas[self.PLAYERORDER[1]].all_in = 1 if (bigblind/2) = playas[self.PLAYERORDER[0]].stacksize: if bigblind == playas[self.PLAYERORDER[0]].stacksize: playas[self.PLAYERORDER[0]].in_front = bigblind/2 playas[self.PLAYERORDER[0]].put_in_pot = bigblind/2 playas[self.PLAYERORDER[0]].stacksize = 0 self.pot += bigblind/2 playas[self.PLAYERORDER[0]].all_in = 1 else: playas[self.PLAYERORDER[0]].put_in_pot = playas[self.PLAYERORDER[0]].stacksize playas[self.PLAYERORDER[0]].in_front = playas[self.PLAYERORDER[0]].stacksize playas[self.PLAYERORDER[0]].stacksize = 0 playas[self.PLAYERORDER[0]].all_in = 1 if playas[self.PLAYERORDER[0]].all_in == 0: playas[self.PLAYERORDER[0]].stacksize -= bigblind/2 playas[self.PLAYERORDER[0]].in_front = bigblind/2 playas[self.PLAYERORDER[0]].put_in_pot = bigblind/2 self.pot += bigblind/2 if playas[self.PLAYERORDER[1]].all_in == 0: playas[self.PLAYERORDER[1]].stacksize -= bigblind playas[self.PLAYERORDER[1]].in_front = bigblind playas[self.PLAYERORDER[1]].put_in_pot = bigblind self.pot += bigblind self.left_to_act = self.PLAYERORDER[:] self.cost_to_play = bigblind self.last_raise = bigblind else: # post blinds for more that 2 players # player has not enough or just enough for big blind if playas[self.PLAYERORDER[2%len(self.PLAYERORDER)]].stacksize = bigblind: if playas[self.PLAYERORDER[2%len(self.PLAYERORDER)]].stacksize bigblind: playas[self.PLAYERORDER[2%len(self.PLAYERORDER)]].put_in_pot = playas[self.PLAYERORDER[2%len(self.PLAYERORDER)]].stacksize playas[self.PLAYERORDER[2%len(self.PLAYERORDER)]].in_front =
Re: generating unique variable name via loops
4 Kasım 2014 Salı 17:01:17 UTC+2 tarihinde Peter Otten yazdı: Fatih Güven wrote: 4 Kasım 2014 Salı 15:37:59 UTC+2 tarihinde Peter Otten yazdı: Veek M wrote: Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) Why would you do this? I have a structured and repetitive data. I was actually asking Veek M. I want to read a .txt file line by line and classified it to call easily. For example employee1 has a name, a salary, shift, age etc. and employee2 and other 101 employee have all of it. Call employee1.name or employee2.salary and assign it to a new variable, something etc. I can only repeat my previous advice. Instead of creating variables for employee1, employee2, and so on make a list of employees: $ cat employees.txt Peter,3000 Paul,2000 Mary,1000 $ cat employees.py #!/usr/bin/env python3 import csv class Employee: def __init__(self, name, salary): self.name = name self.salary = salary if __name__ == __main__: employees = [] with open(employees.txt) as f: for row in csv.reader(f): employees.append(Employee(row[0], int(row[1]))) for employee in employees: print(employee.name, -- salary:, employee.salary, doubloons) $ python3 employees.py Peter -- salary: 3000 doubloons Paul -- salary: 2000 doubloons Mary -- salary: 1000 doubloons You wouldn't want to reference Paul as employee2 -- what if the order in the text file changed? Instead you can make a dict that maps name to employee... employees_by_name = {} for employee in employees: name = employee.name if name in employees_by_name: raise ValueError(duplicate name {}.format(name)) employees_by_name[name] = employee and use that dict to look up an employee: while True: name = input(enter a name ) if name == : print(That's all folks) break if name not in employees_by_name: print(unknown name) else: print(Salary:, employees_by_name[name].salary, doubloons) $ python3 employees.py Peter -- salary: 3000 doubloons Paul -- salary: 2000 doubloons Mary -- salary: 1000 doubloons enter a name Peter Salary: 3000 doubloons enter a name Mary Salary: 1000 doubloons enter a name paul unknown name enter a name Paul Salary: 2000 doubloons enter a name That's all folks $ Thanks for your concern, I will try this. Actually, the main focus is that are there any other Paul in my team. So i want to create a simple ID for employee to distinguish two Paul. I belive that you have a solution for this. -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
Fatih Güven wrote: 4 Kasım 2014 Salı 17:01:17 UTC+2 tarihinde Peter Otten yazdı: Fatih Güven wrote: 4 Kasım 2014 Salı 15:37:59 UTC+2 tarihinde Peter Otten yazdı: Veek M wrote: Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) Why would you do this? I have a structured and repetitive data. I was actually asking Veek M. I want to read a .txt file line by line and classified it to call easily. For example employee1 has a name, a salary, shift, age etc. and employee2 and other 101 employee have all of it. Call employee1.name or employee2.salary and assign it to a new variable, something etc. I can only repeat my previous advice. Instead of creating variables for employee1, employee2, and so on make a list of employees: $ cat employees.txt Peter,3000 Paul,2000 Mary,1000 $ cat employees.py #!/usr/bin/env python3 import csv class Employee: def __init__(self, name, salary): self.name = name self.salary = salary if __name__ == __main__: employees = [] with open(employees.txt) as f: for row in csv.reader(f): employees.append(Employee(row[0], int(row[1]))) for employee in employees: print(employee.name, -- salary:, employee.salary, doubloons) $ python3 employees.py Peter -- salary: 3000 doubloons Paul -- salary: 2000 doubloons Mary -- salary: 1000 doubloons You wouldn't want to reference Paul as employee2 -- what if the order in the text file changed? Instead you can make a dict that maps name to employee... employees_by_name = {} for employee in employees: name = employee.name if name in employees_by_name: raise ValueError(duplicate name {}.format(name)) employees_by_name[name] = employee and use that dict to look up an employee: while True: name = input(enter a name ) if name == : print(That's all folks) break if name not in employees_by_name: print(unknown name) else: print(Salary:, employees_by_name[name].salary, doubloons) $ python3 employees.py Peter -- salary: 3000 doubloons Paul -- salary: 2000 doubloons Mary -- salary: 1000 doubloons enter a name Peter Salary: 3000 doubloons enter a name Mary Salary: 1000 doubloons enter a name paul unknown name enter a name Paul Salary: 2000 doubloons enter a name That's all folks $ Thanks for your concern, I will try this. Actually, the main focus is that are there any other Paul in my team. So i want to create a simple ID for employee to distinguish two Paul. I belive that you have a solution for this. The easiest is to use the index: #!/usr/bin/env python3 import csv class Employee: def __init__(self, name, salary): self.name = name self.salary = salary if __name__ == __main__: employees = [] with open(employees.txt) as f: for row in csv.reader(f): employees.append(Employee(row[0], int(row[1]))) for index, employee in enumerate(employees, 1): print(#{}, name: {}.format(index, employee.name)) while True: index = input(enter an index (1...{}) .format(len(employees))) if index == : print(That's all folks) break index = int(index) -1 employee = employees[index] print(Name: {0.name}, Salary: {0.salary}.format(employee)) If the ID must stay the same for two runs of the script you have to put it into the text file as another column. However, you are soon reaching territory where a database is more convenient than a text file. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
Søren wrote: import ctypes Hi, yeah i kind of liked it - still reading the docs though, Beazley has the Python.h solution so I though I'd try that first. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
Jason Swails wrote: I've submitted a PR to your github repo showing you the changes necessary to get your module working on my computer. Segfaults :p which is an improvement :) open(./_hello.cpython-32mu.so, O_RDONLY) = 5 read(5, \177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\0\1\0\0\0\300\7\0\0\0\0\0\0..., 832) = 832 fstat(5, {st_mode=S_IFREG|0755, st_size=19217, ...}) = 0 getcwd(/root/github/junk/hello, 128) = 24 mmap(NULL, 2101544, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7f65daea5000 mprotect(0x7f65daea6000, 2093056, PROT_NONE) = 0 mmap(0x7f65db0a5000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED| MAP_DENYWRITE, 5, 0) = 0x7f65db0a5000 close(5)= 0 mprotect(0x7f65db0a5000, 4096, PROT_READ) = 0 --- SIGSEGV (Segmentation fault) @ 0 (0) --- -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
On Tue, 2014-11-04 at 21:45 +0630, Veek M wrote: Jason Swails wrote: I've submitted a PR to your github repo showing you the changes necessary to get your module working on my computer. Segfaults :p which is an improvement :) What operating system are you running this on? It works fine for me on Linux: bash$ ls hello.c hello.h hello.py pyhello.c setup.py bash$ python3.4 setup.py build_ext --inplace running build_ext building '_hello' extension creating build creating build/temp.linux-x86_64-3.4 x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/usr/include/python3.4 -c pyhello.c -o build/temp.linux-x86_64-3.4/pyhello.o pyhello.c:15:5: warning: initialization from incompatible pointer type [enabled by default] {hello, py_hello, METH_NOARGS, py_hello_doc}, ^ pyhello.c:15:5: warning: (near initialization for ‘hellomethods[0].ml_meth’) [enabled by default] x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/usr/include/python3.4 -c hello.c -o build/temp.linux-x86_64-3.4/hello.o x86_64-pc-linux-gnu-gcc -pthread -shared build/temp.linux-x86_64-3.4/pyhello.o build/temp.linux-x86_64-3.4/hello.o -L/usr/lib64 -lpython3.4 -o /home/swails/BugHunter/CAPI/Python/junk/hello/_hello.cpython-34.so bash$ python3.4 Python 3.4.1 (default, Aug 24 2014, 10:04:41) [GCC 4.7.4] on linux Type help, copyright, credits or license for more information. import hello hello.hello() hello world 0 You can get rid of the warning by casting py_hello to (PyCFunction)... maybe that's causing your segfault? All the best, Jason -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
Jason Swails wrote: What operating system are you running this on? It works fine for me on Linux: Wheezy Debian, Linux deathstar 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux gcc (Debian 4.7.2-5) 4.7.2 Python 3.2.3 I ran it through gdb - not very useful: (gdb) bt #0 0x0055e1bd in PyModule_Create2 () #1 0x0043a830 in _PyImport_LoadDynamicModule () #2 0x00476d84 in ?? () #3 0x004aa3f9 in ?? () #4 0x00477010 in ?? () #5 0x0048ee8d in ?? () #6 0x004a833b in PyObject_Call () #7 0x004b88c9 in PyEval_EvalFrameEx () #8 0x004cdee7 in PyEval_EvalCodeEx () strace -f python3.2 munmap(0x7f215d4b9000, 4096)= 0 stat(hello.py, {st_mode=S_IFREG|0644, st_size=22, ...}) = 0 stat(_hello, 0x7fff9bd38110) = -1 ENOENT (No such file or directory) stat(_hello.cpython-32mu.so, {st_mode=S_IFREG|0755, st_size=19217, ...}) = 0 open(_hello.cpython-32mu.so, O_RDONLY) = 4 fstat(4, {st_mode=S_IFREG|0755, st_size=19217, ...}) = 0 open(./_hello.cpython-32mu.so, O_RDONLY) = 5 read(5, \177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\0\1\0\0\0\300\7\0\0\0\0\0\0..., 832) = 832 fstat(5, {st_mode=S_IFREG|0755, st_size=19217, ...}) = 0 getcwd(/root/github/junk/hello, 128) = 24 mmap(NULL, 2101544, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7f215b71c000 mprotect(0x7f215b71d000, 2093056, PROT_NONE) = 0 mmap(0x7f215b91c000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED| MAP_DENYWRITE, 5, 0) = 0x7f215b91c000 close(5)= 0 mprotect(0x7f215b91c000, 4096, PROT_READ) = 0 --- SIGSEGV (Segmentation fault) @ 0 (0) --- +++ killed by SIGSEGV +++ Segmentation fault -- https://mail.python.org/mailman/listinfo/python-list
[OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
I intend to write in lowest level of computer programming as a hobby. It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code? What is the lowest level of programming computers that you can write ? Is binary code? Is hex code? Is another machine code? Honestly do not know if it is true that there is another machine code beyond the binary and hex code. Is Assembly? -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On 2014-11-04, françai s romaper...@gmail.com wrote: I intend to write in lowest level of computer programming as a hobby. It is true that is impossible write in binary code, No. You can write in binary if you want. If I were going to do something like that I'd pick a CPU like a PDP11 with a nice simple, regular, orthogonal instruction set. That will minimize the amount of stuff you'll need to memorize. The MSP430 isn't bad either. the lowest level of programming that you can write is in hex code? Hex is just a shorthand notation for binary where a group of 4 bits is represented by a single character 0-9,A-F, but it's the exact same code: binary hex 0 00011 00102 00113 01004 01015 01106 01117 10008 10019 1010A 1011B 1100C 1101D 1110E F What is the lowest level of programming computers that you can write ? Is binary code? Is hex code? They're the same thing. I supposed I could write in hex/binary if I really wanted to. I did it once or twice in the distant past, but it's not something I'd consider fun. The lowest language I actually write code in is assembly. Is another machine code? Honestly do not know if it is true that there is another machine code beyond the binary and hex code. Is Assembly? Assembly is small a step up from binary, where you enter keywords that are translated directly into binary using a simple lookup table. You still have to know all about the CPU's instructions, registers, modes, and so on the same as you do when writing in binary -- you just don't have to memorize exactly which bit patterns are used for which instructions. On many CPUs there is another layer below binary and that's the microcode that runs on the actual CPU gates. The microcode is a little program that interprets the binary code that you're talking about writing. The only people that write microcode are the design engieers where the CPU was designed. If you really want to write in binary, you should probably first learn to program in assembly language as a way to understand the the CPU and it's instruction set and addressing modes. The assmebler will still do all sorts of bookkeeping and keep track of memory addresses for you so that when you insert or remove an instruction you don't have to manually adjust the addresses for the entire rest of the program. -- Grant Edwards grant.b.edwardsYow! A dwarf is passing out at somewhere in Detroit! gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
static PyMethodDef hellomethods[] = { {hello, py_hello, METH_VARARGS, py_hello_doc}, {NULL, NULL, 0, NULL}, }; It's basically the METH_VARARGS field that's giving the problem. Switching it to NULL gives, SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported! and METH_NOARGS doesn't work in 3.2 -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
On Tue, 04 Nov 2014 05:45:04 -0800, Fatih Güven wrote: 4 Kasım 2014 Salı 15:19:20 UTC+2 tarihinde Veek M yazdı: Fatih Güven wrote: 4 Kas?m 2014 Sal? 13:29:34 UTC+2 tarihinde Fatih Güven yazd?: I want to generate a unique variable name for list using python. list1=... list2=... for x in range(1,10): exec(list%d = [] % x) This is okay but i can't use the method .append for example list1.append(abc) This is one solution using a dictionary of lists to maintain the name association. It may not be the best method. It may not be the best solution for you. It may not be the answer your instructor is looking for, and it contains deliberate syntax errors. lists = {} for fn in filenames infile = open(fn, r) lists[fn] = [] for line in infile lists[fn].append(line) infile.close() If you have to ask how to do this sort of thing, you probably shouldn't be coding employee data processing systems anyway! If this was a coding assignment for a course, you should have had sufficient instruction in the relevant algorithms and language features to be able to figure it out yourself. In either case, what not explain what you tried, what you expected it to do, and what it actually did. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
On Tue, 04 Nov 2014 05:53:04 -0800, Fatih Güven wrote: Call employee1.name or employee2.salary and assign it to a new variable, something etc. 1) Put the file into a database. 2) database calls -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
On Tue, Nov 4, 2014 at 11:09 AM, Veek M vek.m1...@gmail.com wrote: static PyMethodDef hellomethods[] = { {hello, py_hello, METH_VARARGS, py_hello_doc}, {NULL, NULL, 0, NULL}, }; It's basically the METH_VARARGS field that's giving the problem. Switching it to NULL gives, SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported! Yes, I got that problem too, which is why I switched it to METH_NOARGS. and METH_NOARGS doesn't work in 3.2 I t does for me: Python 3.2.5 (default, Aug 24 2014, 10:06:23) [GCC 4.7.4] on linux2 Type help, copyright, credits or license for more information. import hello hello.hello() hello world 0 As you can see -- this is a Python 3.2 built with GCC 4.7 (On Gentoo Linux). It also works on Python 3.1 and 3.0 (but obviously doesn't work for Python 2.X). I can't tell why you're having so many problems... Try doing a git clean -fxd to make sure you don't have leftover files lying around somewhere that are causing grief. Also, you need to add -g to the compiler arguments to make sure you build with debug symbols if you want a meaningful traceback. Good luck, Jason -- Jason M. Swails BioMaPS, Rutgers University Postdoctoral Researcher -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
okay got it working - thanks Jason! The 3.2 docs are slightly different. -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On Tuesday, November 4, 2014 10:19:36 PM UTC+5:30, françai s wrote: I intend to write in lowest level of computer programming as a hobby. It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code? What is the lowest level of programming computers that you can write ? Is binary code? Is hex code? Is another machine code? Honestly do not know if it is true that there is another machine code beyond the binary and hex code. Is Assembly? Machines of earlier years had something called microprogramming below the machine language level. After the advent of RISC machines (ie for the last 20 years or so) this is not available to a 'normal' user. [Where by 'normal' user I mean someone who is not an employee of Intel for example]. Classic book for this is Tanenbaum's Structured computer organization. Then below this is a bunch of layers (very remote from programming) which electronics folks deal with going upto the solid-state physics of silicon -- https://mail.python.org/mailman/listinfo/python-list
pkcs7 signing
Is there a way to do pkcs7 / 12 signing with python. I looked at various cryptographic packages, but it's not clear if any of them can do this. -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
Grant's statements are correct and his advice is sound. I would not waste my time writing machine code, even as a hobby (and not even if your other hobbies include juggling chain saws). It's too time-consuming, tedious, bug-prone, and eyeglass-prescription-enhancing. Programming in assembly language will show you how the machine really works, and is challenging enough for almost anyone. And it will help you truly appreciate a powerful high-level language like Python. I've written much assembly language, on two different architectures, over the past 35 years, and I'm glad I did. But these days I work in assembly language only when necessary (legacy code). Give me Python any day! Cheers, Steve J. Martin -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On Tuesday, November 4, 2014 8:49:36 AM UTC-8, françai s wrote: I intend to write in lowest level of computer programming as a hobby. It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code? What is the lowest level of programming computers that you can write ? Is binary code? Is hex code? Is another machine code? Honestly do not know if it is true that there is another machine code beyond the binary and hex code. Is Assembly? I can't think of any reason why someone would WANT to program in binary/hex machine code. If you want to program in a language that is as close to the metal as you can get, just learn Assembly. It will save you many headaches, especially if you're planning on writing for x86 CPUs. The number of opcodes is absurd without even getting into 64-bit instructions, SSE, etc. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
This list is for the development _of_ Python, not development _with_ Python. Try asking on Python List. (forwarding...) On 11/04/2014 08:52 AM, Roberto Martínez wrote: I am trying to replace dinamically the __call__ method of an object using setattr. Example: $ cat testcall.py class A: def __init__(self): setattr(self, '__call__', self.newcall) def __call__(self): print(OLD) def newcall(self): print(NEW) a=A() a() I expect to get NEW instead of OLD, but in Python 3.4 I get OLD. $ python2.7 testcall.py NEW $ python3.4 testcall.py OLD I have a few questions: - Is this an expected behavior? - Is possible to replace __call__ dinamically in Python 3? How? In 2.7 that would be a classic class, about which I know little. In 3.x you have a new class, one which inherits from 'object'. When you replace __call__ you need to replace it the class, not on the instance: setattr(__self__.__class__, self.newcall) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: Python extension using a C library with one 'hello' function
On Tue, 2014-11-04 at 23:03 +0630, Veek M wrote: okay got it working - thanks Jason! The 3.2 docs are slightly different. What did you need to do to get it working? -- https://mail.python.org/mailman/listinfo/python-list
Re: generating unique variable name via loops
On 2014-11-04 05:53, Fatih Güven wrote: for x in range(1,10): exec(list%d = [] % x) Why would you do this? I have a structured and repetitive data. I want to read a .txt file line by line and classified it to call easily. For example employee1 has a name, a salary, shift, age etc. and employee2 and other 101 employee have all of it. Call employee1.name or employee2.salary and assign it to a new variable, something etc. -- This sounds remarkably like a CSV or tab-delimited file. If so, the way to do it would be import csv with open(data.txt, rb) as f: dr = csv.DictReader(f) for row in dr: do_something(row[Name], row[salary]) If the file format is more complex, it's often useful to create a generator to simplify the logic: class Person: def __init__(self, name=, salary=0, shift=, ): self.name = name self.salary = salary self.shift = shift def various_person_methods(self, ...): pass def people_from_file(f): build Person objects as you iterate over the file for row in file: person = Person( ... ) yield person with open(data.txt, r): for person in people_from_file(f): do_something(person) You can then reuse that generator with multiple files if you need. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
sohcahto...@gmail.com a écrit dans le message de news:e5c95792-f81f-42b4-9996-5545f5607...@googlegroups.com... On Tuesday, November 4, 2014 8:49:36 AM UTC-8, françai s wrote: I can't think of any reason why someone would WANT to program in binary/hex machine code. It happens if you design yourself a specialized microcoded machine, also known as a number cruncher and you dont want to developp assembly tools to program it. So you have to fill a memory with 0 and 1 It's sometimes the work of electronic engineers, chip designers. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
Yikes, I didn't realize the difference in inheritance. The thing with this is tricky. I need the change in the instance, not in the class, because I have multiple instances and all of them must have different implementations of __call__. The workaround of calling a different method inside __call__ is not valid for my case because I want to change the *signature* of the function also -for introspection reasons. Thank you all. Best regards, Roberto (Ethan, sorry for posting to python-dev, I thought that it was an implementation detail of CPython 3.X) On Tue, Nov 4, 2014 at 7:23 PM, Ethan Furman et...@stoneleaf.us wrote: This list is for the development _of_ Python, not development _with_ Python. Try asking on Python List. (forwarding...) On 11/04/2014 08:52 AM, Roberto Martínez wrote: I am trying to replace dinamically the __call__ method of an object using setattr. Example: $ cat testcall.py class A: def __init__(self): setattr(self, '__call__', self.newcall) def __call__(self): print(OLD) def newcall(self): print(NEW) a=A() a() I expect to get NEW instead of OLD, but in Python 3.4 I get OLD. $ python2.7 testcall.py NEW $ python3.4 testcall.py OLD I have a few questions: - Is this an expected behavior? - Is possible to replace __call__ dinamically in Python 3? How? In 2.7 that would be a classic class, about which I know little. In 3.x you have a new class, one which inherits from 'object'. When you replace __call__ you need to replace it the class, not on the instance: setattr(__self__.__class__, self.newcall) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez robertomartin...@gmail.com wrote: The workaround of calling a different method inside __call__ is not valid for my case because I want to change the *signature* of the function also -for introspection reasons. You could define __call__ like so: def __call__(self, *args, **kwds): self._my_call(*args, **kwds) then set self._my_call at runtime. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: Code review
- Original Message - From: C Smith illusiontechniq...@gmail.com To: python-list@python.org Sent: Tuesday, 4 November, 2014 4:28:33 PM Subject: Code review I was wondering if I could get some feedback on the biggest thing I have done as an amateur Python coder. The sidepots algorithm isn't correct yet, but I haven't worked on it in a while and thought I would get some advice before diving back in. import random, os ## class Table(object): def __init__(self,bigblind=20,PLAYERNUM=0,pot=0,PLAYERORDER=None, hand_done=0,\ left_to_act=None,cost_to_play=0,in_hand=None,last_raise=0,cards_in_play=None,round='preflop'): if cards_in_play is None: cards_in_play = [] if in_hand is None: in_hand = [] if PLAYERORDER is None: PLAYERORDER = [] if left_to_act is None: left_to_act = [] [snip hundreds of code lines] - Most methods have too much code, split methods into more unitary logical functions. - For instance, add classes 'Hand' and 'Card' - not enough comments - have you written some tests? The code reached a reasonable size where tests would be very helpful (module unittest) - why do you use uppercase attributes ? like PLAYERORDER. These are not 'constants', you change them Example of (incomplete) Card and Hand implementation (python 2.7): class Card(object): Card implementation. def __init__(self, suit, rank): self._suit = suit self._rank = rank # write test card1 == card2 def __eq__(self, other): return (self.suit, self.rank) == (other.suit, other.rank) # use cards as dict keys def __hash__(self): return hash(self.suit, self.rank) # will allow python to sort a list of cards def __lt__(self, other): return int(self) int(other) def __int__(self): Return the numerical value of a card # the dictionary is incomplete return {'1':1,'2':2,'J':11,'Q':12}[self.rank] def __str__(self): return 'Card(%s of %s)' % (self.rank, self.suit) # alias in case card.rank has more meaning than int(card) @property def rank(self): return int(self) # read only access to suit @property def suit(self): return self._suit class Hand(object): Short incomplete example of Hand class def __init__(self): self._cards = [] def add(self, card): if not self.full: self._cards.append(card) if card.rank == 14: # it's an Ace # trick to get Ace considered as 1 as well self._cards.append(Card(card.suite, '1')) # generate the ordered sequence of cards, hiding the '1' cards @property def cards(self): return (card for card in sorted(self._cards) if card.rank 1) # allow to write len(hand) def __len__(self): return len(list(self.cards)) #property def full(self): return len(self) == 5 # allow to write 'for card in hand:' def __iter__(self): return iter(self.cards) def remove(self, card): # and so on... Otherwise: replace if left_to_act is None: left_to_act = [] self.left_to_act = left_to_act by self.left_to_act = left_to_act or [] replace if ranky == 9 or ranky == 5 by if ranky in [9,5] replace if foo == True by if foo replace if len(self.left_to_act) == 0 by if self.left_to_act And much more... but honestly, there's too much code :) I'll let you chew on this one. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On 11/04/2014 11:01 AM, Roberto Martínez wrote: Yikes, I didn't realize the difference in inheritance. The thing with this is tricky. I need the change in the instance, not in the class, because I have multiple instances and all of them must have different implementations of __call__. The workaround of calling a different method inside __call__ is not valid for my case because I want to change the *signature* of the function also -for introspection reasons. If you really absolutely positively have to have the signature be correct for each instance, you may to either look at a function creating factory, a class creating factory, or a meta-class. The first option may work if you don't need an actual class, both of the last two options will be creating different classes, probably with one instance each (unless you have several instances which could share the same __call__). -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On 11/04/2014 11:01 AM, Roberto Martínez wrote: (Ethan, sorry for posting to python-dev, I thought that it was an implementation detail of CPython 3.X) No worries. It's good practice to post here first, just in case. ;) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On Tue, Nov 4, 2014 at 8:06 PM, Skip Montanaro skip.montan...@gmail.com wrote: On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez robertomartin...@gmail.com wrote: The workaround of calling a different method inside __call__ is not valid for my case because I want to change the *signature* of the function also -for introspection reasons. You could define __call__ like so: def __call__(self, *args, **kwds): self._my_call(*args, **kwds) This was my first approach, but it is not very informative to the user and I prefer to have arguments with descriptive names. We have to change __doc__ too, so this is not an ideal solution for me. I tried to implement __getattribute__, but is not called either. :( then set self._my_call at runtime. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On Tue, Nov 4, 2014 at 7:15 PM, Roberto Martínez robertomartin...@gmail.com wrote: On Tue, Nov 4, 2014 at 8:06 PM, Skip Montanaro skip.montan...@gmail.com wrote: On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez robertomartin...@gmail.com wrote: The workaround of calling a different method inside __call__ is not valid for my case because I want to change the *signature* of the function also -for introspection reasons. You could define __call__ like so: def __call__(self, *args, **kwds): self._my_call(*args, **kwds) This was my first approach, but it is not very informative to the user and I prefer to have arguments with descriptive names. We have to change __doc__ too, so this is not an ideal solution for me. I tried to implement __getattribute__, but is not called either. :( I'd suggest starting a new thread on python-list (or stack overflow or whatever) explaining what the heck you're trying to do here and asking for higher-level advice/suggestions, because your current implementation strategy seems to have placed you on a path that is rapidly descending past spaghetti towards tentacular. (Or alternatively I guess you could go all in: Iä! Iä! Metaclasses Fhtagn!) -n -- Nathaniel J. Smith Postdoctoral researcher - Informatics - University of Edinburgh http://vorpus.org -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On Tuesday, November 4, 2014 10:51:53 AM UTC-8, ast wrote: sohcahtoa82 a écrit dans le message de news:e5c95792-f81f-42b4-9996-5545f5607...@googlegroups.com... On Tuesday, November 4, 2014 8:49:36 AM UTC-8, françai s wrote: I can't think of any reason why someone would WANT to program in binary/hex machine code. It happens if you design yourself a specialized microcoded machine, also known as a number cruncher and you dont want to developp assembly tools to program it. So you have to fill a memory with 0 and 1 It's sometimes the work of electronic engineers, chip designers. Well, yeah, that's pretty obvious, but I think that's a bit outside the scope of this discussion. The OP didn't mention designing a chip. -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On 11/04/2014 08:45 AM, françai s wrote: I intend to write in lowest level of computer programming as a hobby. It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code? What is the lowest level of programming computers that you can write ? Is binary code? Is hex code? My first computers at home were Z80 powered Timex's. I tried writing video games in BASIC, but the machines were to slow to animate anything at reasonable speeds. I knew about machine language from a high-school computer course (using and Apple IIe). I bought a book on the Z80, and started reading. My Z80 manual showed each 8-bit instruction's anatomy in Hex and binary. Some of the instructions used several bits to denote some aspect of the instruction. I got some graph paper, and started coding that way, using one square per bit, and one line per byte. I translated all the binary by brain into integer, and used BASIC programs to 'poke' the bytes into memory then execute at the starting address. This was all quite educational and extremely tedious. Eventually, when I found out that assemblers existed, I wrote a crude one in BASIC, and found that to be a luxury. Later when I got an Atari 800, and the assembler cartridge I actually wrote a working two player Tron type game in assembly. Having delved into all of this, I'd like to echo the sentiments of a previous poster, that assembly is really the place to start for a low level language. You get all of the control of machine language, with far less of the headaches. Depending on what you want out of your hobby, if a working program that is of some use is one of those things, then start with assembly. If you just want to geek out and write a program that can guess a number between 1 and 100 by using graph paper, then sure, go for binary writing. -- https://mail.python.org/mailman/listinfo/python-list
Problem adding a Key Value pair
I am trying to add a key value pair of (Priority:1) to queue1, (Priority:2) to queue2, and (Priority:3) to queue3. When I just add (Priority:1) to queue1, it works. But when I run the above code, (Priority:3) is being added to all the queues. This looks trivial and I don't understand why this is happening. Is there something wrong with what I am doing? json_split = {} value = {Status: Submitted, m_Controller: Python} a = range(31) del a[0] for i in a: json_split[i] = value keys = json_split.keys() order = list(keys) q1 = int(round(len(keys)*0.2)) q2 = int(round(len(keys)*0.3)) q3 = int(round(len(keys)*0.5)) b = [q1,q2,q3] n=0 threedicts = [] for i in b: queues = order[n:n+i] n = n+i lists = [(queues[j], json_split.get(queues[j])) for j in range(len(queues))] onedict = {} for q in queues: onedict[q] = json_split[q] threedicts.append (onedict) queue1, queue2, queue3 = threedicts keys1 = queue1.keys() for i in keys1: queue1[i]['Priority'] = ['1'] keys2 = queue2.keys() for j in keys2: queue2[j]['Priority'] = ['2'] keys3 = queue3.keys() for z in keys3: queue3[z]['Priority'] = ['3'] -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On 11/04/2014 11:23 AM, Nathaniel Smith wrote: (Or alternatively I guess you could go all in: Iä! Iä! Metaclasses Fhtagn!) Metaclasses aren't that bad! I've written one. And the dizzy spells are getting better! -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On 2014-11-04, ast nom...@invalid.com wrote: sohcahto...@gmail.com a écrit dans le message de news:e5c95792-f81f-42b4-9996-5545f5607...@googlegroups.com... On Tuesday, November 4, 2014 8:49:36 AM UTC-8, françai s wrote: I can't think of any reason why someone would WANT to program in binary/hex machine code. It happens if you design yourself a specialized microcoded machine, also known as a number cruncher and you dont want to developp assembly tools to program it. It only takes a couple hours to write a half decent two-pass absolute assembler in Python. I've done it. There are also generic assember toolkits/frameworks available. Doing real work in binary is insane. I know people _think_ they're're only going to spend an hour writing just this one program in binary, so it's not worth spending a few hours developing tools. IME, they're always wrong. So you have to fill a memory with 0 and 1 It's sometimes the work of electronic engineers, chip designers. -- Grant Edwards grant.b.edwardsYow! Did I say I was at a sardine? Or a bus??? gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Idle on Mac issues
In article m3ajif$30o$1...@virtdiesel.mng.cu.mi.it, Andrea D'Amore anddamnopsam+gru...@brapi.net wrote: On 2014-11-04 12:43:59 +, Rustom Mody said: I seem to be stuck with some issues of Idle on macs. The page https://www.python.org/download/mac/tcltk seems to talk only of Tcl/Tk versions 8.5 System's 8.5 should be enough, if not there's explicit mention of the ActiveTcl distribution. The Tcl/Tk 8.5.x versions shipped by Apple since OS X 10.6, and including 10.10, lag behind the current releases of Tcl/Tk; all Apple 8.5 version have serious bugs that have been fixed upstream. The most serious involves an immediate, unrecoverable crash in Tk when typing a composition character in an edit window or the IDLE shell, for example option-u (to make an umlaut) with a US input method. That's why we strongly urge IDLE users to *not* use the Apple-supplied Tcl/Tk. (The Apple-supplied Tk 8.5 with OS X 10.6 is pretty much unusable with IDLE.) Unfortunately, it's not trivial nor advisable to modify the system-supplied Python to use a newer third-party Tcl/Tk. The Pythons provide by the python.org OS X binary installers will automatically use a third-party Tcl/Tk 8.5.x installed in /Library/Frameworks (like ActiveTcl 8.5) and fall back to the system Tcl/Tk 8.5 in /System/Library/Frameworks. Since Apple does not currently ship Tcl/Tk 8.6, the python.org OS X binary installer Pythons currently do not support 8.6, either. Macports seem to have at 8.6 https://www.macports.org/ports.php?by=librarysubstr=tcl But that won't likely be used by a binary python installation, unless you're using python from MacPorts as well. Yes, but, if you are using MacPorts, you should use one of its Python anyway. Note that the MacPorts Tk 8.6 has two variants: +quartz (for the native Cocoa Tk) and +x11 (for a traditional X11-based Tk). Because of many odd implementation choices with X11 and X11 Tk on OS X, I do not recommend using the X11 Tk on OS X with IDLE. I'm on 10.10 (happily) running MacPorts, I have system's python 2.7.6 as well as 2.7.8 and 3.4.2 from MacPorts, these two built with Xquartz support. I can start the idle binary provided by all of those, the system's with native GUI, and have working Options menu in all of them. BTW, there have been various tweaks to IDLE's Preferences and Options menus in recent releases of Python. You are well-advised to use the latest versions of Python, currently 3.4.2 and 2.7.8, to get the best experience with IDLE. I'd suggest the people having issue to describe their issues here, with details on the system version, python version, the exact command they run and the error they get. Good suggestion. Also, it would be a good idea to check the Python bug tracker, bugs.python.org, for existing problem reports and to open new issues if none found. -- Ned Deily, n...@acm.org -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem adding a Key Value pair
On 2014-11-04 19:37, Anurag Patibandla wrote: I am trying to add a key value pair of (Priority:1) to queue1, (Priority:2) to queue2, and (Priority:3) to queue3. When I just add (Priority:1) to queue1, it works. But when I run the above code, (Priority:3) is being added to all the queues. This looks trivial and I don't understand why this is happening. Is there something wrong with what I am doing? json_split = {} value = {Status: Submitted, m_Controller: Python} a = range(31) del a[0] That's better as: a = range(1, 31) for i in a: json_split[i] = value Here the key will be whatever 'i' refers to (1..30) and the value will be the dict referred to by 'value'. Try adding the line: print json_split[1] is json_split[2] It'll print out 'True'; it's saying that they are the same dict. You want the values of json_split to be _separate_ dicts. The fix is simple. Just make a copy of the dict for each one: for i in a: json_split[i] = dict(value) [snip] -- https://mail.python.org/mailman/listinfo/python-list
Re: Code review
C Smith illusiontechniq...@gmail.com writes: I was wondering if I could get some feedback on the biggest thing I have done as an amateur Python coder. Comments. You need a *lot* more comments. Like, every line or two of code should have a comment explaining what is being accomplished. Seriously. Every line or two. Some blank lines wouldn't hurt either. Also it would be nice to define some of the terms you're using. What is a blind? What does in front mean? What is a muck hand? -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem adding a Key Value pair
On Tuesday, November 4, 2014 2:37:49 PM UTC-5, Anurag Patibandla wrote: I am trying to add a key value pair of (Priority:1) to queue1, (Priority:2) to queue2, and (Priority:3) to queue3. When I just add (Priority:1) to queue1, it works. But when I run the above code, (Priority:3) is being added to all the queues. This looks trivial and I don't understand why this is happening. Is there something wrong with what I am doing? json_split = {} value = {Status: Submitted, m_Controller: Python} a = range(31) del a[0] for i in a: json_split[i] = value keys = json_split.keys() order = list(keys) q1 = int(round(len(keys)*0.2)) q2 = int(round(len(keys)*0.3)) q3 = int(round(len(keys)*0.5)) b = [q1,q2,q3] n=0 threedicts = [] for i in b: queues = order[n:n+i] n = n+i lists = [(queues[j], json_split.get(queues[j])) for j in range(len(queues))] onedict = {} for q in queues: onedict[q] = json_split[q] threedicts.append (onedict) queue1, queue2, queue3 = threedicts keys1 = queue1.keys() for i in keys1: queue1[i]['Priority'] = ['1'] keys2 = queue2.keys() for j in keys2: queue2[j]['Priority'] = ['2'] keys3 = queue3.keys() for z in keys3: queue3[z]['Priority'] = ['3'] Awesome! Thank you!! -- https://mail.python.org/mailman/listinfo/python-list
Re: Idle on Mac issues
On 2014-11-04 19:55:00 +, Ned Deily said: […] all Apple 8.5 version have serious bugs that have been fixed upstream. The most serious involves an immediate, unrecoverable crash in Tk when typing a composition character in an edit window or the IDLE shell […] I stand corrected, I wasn't aware of these issues since I've always used the version available in ports. Note that the MacPorts Tk 8.6 has two variants: +quartz (for the native Cocoa Tk) and +x11 (for a traditional X11-based Tk).Because of many odd implementation choices with X11 and X11 Tk on OS X, I do not recommend using the X11 Tk on OS X with IDLE. I know, I'm using tk +x11 on purpose due to an issue with a specific program and the +quartz version. You are well-advised to use the latest versions of Python, currently 3.4.2 and 2.7.8, to get the best experience with IDLE. I mentioned the slightly outdated 2.7.6 as that's the one shipped with the system and it's better not to tinker with it, IIRC there are system scripts relying on it. -- Andrea -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
You could go to http://incolor.inetnebr.com/bill_r/computer_simulators.htm and get the Altair 8800 or IMSAI 8080 emulator. Run the program and toggle in binary code for these easy to use 8 bit processors. There's a short manual for the IMSAI on the same page and the manual plus instruction set for the Altair can be found in http://www.classiccmp.org/dunfield/altair/d/88opman.pdf. Have fun with binary, I wish these machine were still available. Theo On 4-11-2014 17:45, françai s wrote: I intend to write in lowest level of computer programming as a hobby. It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code? What is the lowest level of programming computers that you can write ? Is binary code? Is hex code? Is another machine code? Honestly do not know if it is true that there is another machine code beyond the binary and hex code. Is Assembly? -- https://mail.python.org/mailman/listinfo/python-list
Re: Code review
On Tuesday, November 4, 2014 12:35:32 PM UTC-8, John Gordon wrote: C Smith illusiontechniq...@gmail.com writes: I was wondering if I could get some feedback on the biggest thing I have done as an amateur Python coder. Comments. You need a *lot* more comments. Like, every line or two of code should have a comment explaining what is being accomplished. Seriously. Every line or two. Some blank lines wouldn't hurt either. Also it would be nice to define some of the terms you're using. What is a blind? What does in front mean? What is a muck hand? -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. A blind is a required bet that the two people sitting to the left of the button have to make before a hand begins. The first player pays the small blind and the second player pays the big blind, which is double the small blind. For tournament games, the blinds increase periodically. Mucking a hand means to throw your cards away without revealing them. In professional Poker, you typically give them to the dealer. In front just refers to table position which determines play order. -- https://mail.python.org/mailman/listinfo/python-list
Re: simple download manager
On Tuesday, November 4, 2014 4:10:59 PM UTC+1, Kiuhnm wrote: On Tuesday, November 4, 2014 4:00:51 PM UTC+1, Chris Angelico wrote: On Wed, Nov 5, 2014 at 1:53 AM, Kiuhnm gandal...@mail.com wrote: I wish to automate the downloading from a particular site which has some ADs and which requires to click on a lot of buttons before the download starts. What library should I use to handle HTTP? Also, I need to support big files ( 1 GB) so the library should hand the data to me chunk by chunk. You may be violating the site's terms of service, so be aware of what you're doing. This could be a really simple job (just figure out what the last HTTP query is, and replicate that), or it could be insanely complicated (crypto, JavaScript, and/or timestamped URLs could easily be involved). To start off, I would recommend not writing a single like of Python code, but just pulling up Mozilla Firefox with Firebug, or Google Chrome with in-built inspection tools, or some equivalent, and watching the exact queries that go through. Once you figure out what queries are happening, you can figure out how to do them in Python. ChrisA It'll be tricky. I'm sure of that, but if the browser can do it, so can I :) Fortunately, there are no captchas. There are no captcha but the site is behind cloudflare (DDOS protection). Anyway, I now know what to do. To deal with cloudflare's javascript challenge I'm going to use jsdb, a neat little javascript interpreter. By the way, I'm using requests instead of urllib, but I need to figure out how to download and write to disk big files. -- https://mail.python.org/mailman/listinfo/python-list
detect mouse pointer type
Hello, please how can I detect mouse pointer type? I would like to print every mouse pointer change (arrow, hand, ...) while moving my mouse over screen. How can I do this? (for now I need it for windows, but cross-platform solution is highly appreciated) Many thanks. -- https://mail.python.org/mailman/listinfo/python-list
check_output
When I call subprocess.check_output() I see the console window appear and disappear very quickly. Is there a way to stop the console from showing up at all? -- https://mail.python.org/mailman/listinfo/python-list
Re: check_output
On Wednesday, November 5, 2014 3:05:32 AM UTC+1, Kiuhnm wrote: When I call subprocess.check_output() I see the console window appear and disappear very quickly. Is there a way to stop the console from showing up at all? shell=True does the trick! -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On Wed, Nov 5, 2014 at 1:30 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: machine code typically implies an instruction set specific to that machine... ALL computers operate in BINARY logic (a bit only holds 0 or 1). How you get those bits into the computer is irrelevant. Bah, those zeroes and ones are just an abstraction! They work in voltages. Actually, those voltages are just an abstraction. They work in electrons. Not to mention that electrons are really abstractions too, in their own way... ChrisA -- https://mail.python.org/mailman/listinfo/python-list
What is the difference between these two? (Assigning functions to variables)
Example 1 def compose_greet_func(): def get_message(): return Hello there! return get_message greet = compose_greet_func() print greet() Example 2 def greet(name): return hello +name greet_someone = greet print greet_someone(John In Example 1, the function compoe_greet_func is assigned to the variable greet, and () is included at the end of the function. However, in Example 2, the function greet is assigned to the variable greet_someone but () is excluded at the end of the function. Does the () matter when assigning functions to variables? Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the difference between these two? (Assigning functions to variables)
Just to be clear, I was referring to these two lines greet = compose_greet_func() greet_someone = greet On Wednesday, November 5, 2014 11:15:46 AM UTC+8, Max Nathaniel Ho wrote: Example 1 def compose_greet_func(): def get_message(): return Hello there! return get_message greet = compose_greet_func() print greet() Example 2 def greet(name): return hello +name greet_someone = greet print greet_someone(John In Example 1, the function compoe_greet_func is assigned to the variable greet, and () is included at the end of the function. However, in Example 2, the function greet is assigned to the variable greet_someone but () is excluded at the end of the function. Does the () matter when assigning functions to variables? Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On 11/04/2014 08:52 AM, Roberto Martínez wrote: I am trying to replace dinamically the __call__ method of an object using setattr. Example: $ cat testcall.py class A: def __init__(self): setattr(self, '__call__', self.newcall) def __call__(self): print(OLD) def newcall(self): print(NEW) a=A() a() I expect to get NEW instead of OLD, but in Python 3.4 I get OLD. Given that special methods can only be replaced on the class and not the instance, you could create a new version of the class within __init__ and assign it to the instance: class A: def __init__(self, call_method=None): if call_method: methods = {'__call__': call_method} self.__class__ = type('Custom_A', (A,), ) def __call__(self): return 'original' a = A() a() old b = A(lambda self: 'new') b() new -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the difference between these two? (Assigning functions to variables)
On 04Nov2014 19:17, Max Nathaniel Ho maxhow...@gmail.com wrote: Just to be clear, I was referring to these two lines greet = compose_greet_func() greet_someone = greet Please don't top-post. Thanks. Your first assignment: greet = compose_greet_func() _calls_ (runs) the compose_greet_func and assigns its return value to greet. Your second assignment: greet_someone = greet assigns the current value of greet, whatever that is, to greet_someone. No function is called. Cheers, Cameron Simpson c...@zip.com.au -- https://mail.python.org/mailman/listinfo/python-list
Re: Code review
Jean-Michel wrote: replace if left_to_act is None: left_to_act = [] self.left_to_act = left_to_act by self.left_to_act = left_to_act or [] I read that with 2.7 that I had to initialize class variables to immutable types. I think because I was working with the lists before they had been altered and were still empty lists. I will mess around tomorrow with the classes you suggested as I have yet to make use of decorators. Thanks. I will work on putting some more comments in as well. On Tue, Nov 4, 2014 at 4:09 PM, sohcahto...@gmail.com wrote: On Tuesday, November 4, 2014 12:35:32 PM UTC-8, John Gordon wrote: C Smith illusiontechniq...@gmail.com writes: I was wondering if I could get some feedback on the biggest thing I have done as an amateur Python coder. Comments. You need a *lot* more comments. Like, every line or two of code should have a comment explaining what is being accomplished. Seriously. Every line or two. Some blank lines wouldn't hurt either. Also it would be nice to define some of the terms you're using. What is a blind? What does in front mean? What is a muck hand? -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. A blind is a required bet that the two people sitting to the left of the button have to make before a hand begins. The first player pays the small blind and the second player pays the big blind, which is double the small blind. For tournament games, the blinds increase periodically. Mucking a hand means to throw your cards away without revealing them. In professional Poker, you typically give them to the dealer. In front just refers to table position which determines play order. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On 04Nov2014 11:24, sohcahto...@gmail.com sohcahto...@gmail.com wrote: On Tuesday, November 4, 2014 10:51:53 AM UTC-8, ast wrote: sohcahtoa82 a écrit dans le message de news:e5c95792-f81f-42b4-9996-5545f5607...@googlegroups.com... On Tuesday, November 4, 2014 8:49:36 AM UTC-8, françai s wrote: I can't think of any reason why someone would WANT to program in binary/hex machine code. It happens if you design yourself a specialized microcoded machine, also known as a number cruncher and you dont want to developp assembly tools to program it. So you have to fill a memory with 0 and 1 It's sometimes the work of electronic engineers, chip designers. Well, yeah, that's pretty obvious, but I think that's a bit outside the scope of this discussion. The OP didn't mention designing a chip. Bah! He asked if there were lower levels than binary. Ergo: chip design! (And microcode, the intermediate layer. Or one of the layers, depending where you draw the line.) Should we stop before we reach the quantum foam of spacetime? Cheers, Cameron Simpson c...@zip.com.au -- https://mail.python.org/mailman/listinfo/python-list
Re: pkcs7 signing
Robin Becker ro...@reportlab.com writes: Is there a way to do pkcs7 / 12 signing with python. Have you checked whether OpenSSL supports this kind of signing? If it does, then you likely can use this via several Python wrappings for OpenSSL. -- https://mail.python.org/mailman/listinfo/python-list
Python, VIM: namespace, scope, life of a python object stuck in a HERE
If i have two functions: function! foo() python3 HERE import mylib pass HERE function! bar() python3 HERE import mylib pass HERE The src says: 1. Python interpreter main program 3. Implementation of the Vim module for Python So, is the python interpreter embedded in vim AND additionally, are separate extensions to python provided (wrapper functions for the VIM API). Mixed bindings? How many times is mylib compiled to bytecode and loaded? Does each vimscript function get its own mylib - can I instantiate something and expect it to be visible in the other function? I have a bunch of leader (\)-functions that share similar code and act on the same buffer so I wanted to know if I could reuse that data-structure. How many times is the interpreter loaded into memory: once obviously at vim runtime. -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On Wed, Nov 5, 2014 at 5:39 PM, Cameron Simpson c...@zip.com.au wrote: Bah! He asked if there were lower levels than binary. Ergo: chip design! (And microcode, the intermediate layer. Or one of the layers, depending where you draw the line.) Should we stop before we reach the quantum foam of spacetime? Certainly not. We keep going below electrons, and find ourselves in Quantumland. It's like Wonderland, only... uhh... actually, it's just like Wonderland. Pick up a book called Alice in Quantumland by Robert Gilmore - it's worth reading. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the difference between these two? (Assigning functions to variables)
On Wednesday, November 5, 2014 2:00:08 PM UTC+8, Cameron Simpson wrote: On 04Nov2014 19:17, Max Nathaniel Ho maxhow...@gmail.com wrote: Just to be clear, I was referring to these two lines greet = compose_greet_func() greet_someone = greet Please don't top-post. Thanks. Your first assignment: greet = compose_greet_func() _calls_ (runs) the compose_greet_func and assigns its return value to greet. Your second assignment: greet_someone = greet assigns the current value of greet, whatever that is, to greet_someone. No function is called. Cheers, Cameron Simpson c...@zip.com.au Apologies about the top posting. Ahh okay, thank you for your explanation -- https://mail.python.org/mailman/listinfo/python-list
Re: Python, VIM: namespace, scope, life of a python object stuck in a HERE
Veek M wrote: If i have two functions: function! foo() python3 HERE import mylib pass HERE function! bar() python3 HERE import mylib pass HERE The src says: 1. Python interpreter main program 3. Implementation of the Vim module for Python So, is the python interpreter embedded in vim AND additionally, are separate extensions to python provided (wrapper functions for the VIM API). Mixed bindings? How many times is mylib compiled to bytecode and loaded? Does each vimscript function get its own mylib - can I instantiate something and expect it to be visible in the other function? I have a bunch of leader (\)-functions that share similar code and act on the same buffer so I wanted to know if I could reuse that data-structure. How many times is the interpreter loaded into memory: once obviously at vim runtime. I'm not a vim user and I only got to work something similar with Python 2. I put print hello into mylib.py and saw when it was printed with the following script: function! Foo() python HERE import sys sys.path.append(.) import mylib HERE endfunction function! Bar() python HERE import mylib HERE endfunction :so vimscript.txt :call Foo() -- hello :call Bar() -- (nothing) Conclusion: both functions share the same Python interpreter. With a function containing import os print os.getpid() you can also see that the Python interpreter runs in the same process as vim. -- https://mail.python.org/mailman/listinfo/python-list
[issue22780] NotImplemented doc section needs update
R. David Murray added the comment: try the reflected operation is not our standard terminology. There is a reason I suggested *copying* the parenthetical statement. We essentially have two places where NotImplemented is described (language reference and library reference), and the parenthetical is the only substantial piece of information present in one that is not present in the other. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22780 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22725] improve documentation for enumerate() (built-in function)
R. David Murray added the comment: Specifically, this works (in 2.7): enumerate(sequence=myvar) Changing sequence to iterable would break any code that was written like the above. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22725 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] __qualname__ missing from dir(__class__) during class initialisation
New submission from Sam Bishop: The output of performing dir(__class__) during a class' __init__ method, seems to be lacking the new '__qualname__' attribute in python 3. This rough test can be pasted right into the python 3.4 REPL to see the issue. Tested on 64bit python 3.4 running on OSX 10.9 class Foo: class Bar(object): keywords = dict() def __init__(self, **kwargs): print(dir(__class__)) print(''.join(('str(__class__.__qualname__) = ', str(__class__.__qualname__ print(''.join(( 'Is __qualname__ in the output of the dir() function? : ', str(('__qualname__' in dir(__class__)) self.keywords = kwargs test = Foo.Bar(see='We are missing something here') -- components: Interpreter Core messages: 230591 nosy: techdragon priority: normal severity: normal status: open title: __qualname__ missing from dir(__class__) during class initialisation type: behavior versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22791] datetime.utcfromtimestamp() shoud have option for create tz aware datetime
New submission from INADA Naoki: In [1]: import datetime In [2]: datetime.datetime.utcfromtimestamp(0) Out[2]: datetime.datetime(1970, 1, 1, 0, 0) In [3]: datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc) Out[3]: datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc) datetime.utcfromtimestamp() returns naive datetime. But some methods assumes naive datetime is localtime. (e.g. datetime.timestamp()). This is big pitfall for many Pythonistas. We can't change default behavior for backward compatibility. How about adding `aware` keyword-only option? datetime.datetime.utcfromtimestamp(0, aware=True) datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc) -- components: Library (Lib) messages: 230592 nosy: naoki priority: normal severity: normal status: open title: datetime.utcfromtimestamp() shoud have option for create tz aware datetime type: enhancement versions: Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22791 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] __qualname__ missing from dir(__class__) during class initialisation
Amaury Forgeot d'Arc added the comment: Why did you specify during class initialization only? When I print dir(Foo.Bar) at top-level, there is no __qualname__. Then, note that '__name__' is not listed either, so it's not about new attributes. It was chosen that dir(someClass) tries to list the know attributes of instances, not the attributes of the class object itself (__bases__, __mro__, and so on). See https://docs.python.org/3.4/library/functions.html#dir -- nosy: +amaury.forgeotdarc resolution: - works for me status: open - pending ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
Georg Brandl added the comment: @Amaury: this is not what I read there: If the object is a type or class object, the list contains the names of its attributes, and recursively of the attributes of its bases. This implies that class attributes are definitely supposed to be in there. -- nosy: +georg.brandl resolution: works for me - status: pending - open title: __qualname__ missing from dir(__class__) during class initialisation - some class attributes missing from dir(Class) ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
Sam Bishop added the comment: I specified 'during class initialisation' because that was the only case I confirmed. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
Georg Brandl added the comment: The missing attributes are some of those defined in type_getsets, i.e. __name__ __qualname__ __bases__ __abstractmethods__ __text_signature__ The latter two are obscure enough that it probably doesn't matter, but the first three should definitely be there. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
Georg Brandl added the comment: Ah yes, and some type_members are also missing. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
eryksun added the comment: You won't find the __qualname__ data descriptor in dir(Foo.Bar) because it's defined by the metaclass, `type`. Attributes from the metaclass have always been excluded from the dir() of a class. -- nosy: +eryksun ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
eryksun added the comment: See type_dir: https://hg.python.org/cpython/file/ab2c023a9432/Objects/typeobject.c#l2984 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22789] Compress the marshalled data in PYC files
Antoine Pitrou added the comment: This is similar to the idea of loading the stdlib from a zip file (but less intrusive and more debugging-friendly). The time savings will depend on whether the filesystem cache is cold or hot. In the latter case, my intuition is that decompression will slow things down a bit :-) Quick decompression benchmark on a popular stdlib module, and a fast CPU: $ ./python -m timeit -s import zlib; data = zlib.compress(open('Lib/__pycache__/threading.cpython-35.pyc', 'rb').read()) zlib.decompress(data) 1 loops, best of 3: 180 usec per loop -- nosy: +tim.peters ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22789 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22792] string replace() not documented
New submission from housetier: https://docs.python.org/3.4/library/string.html does not explain the replace() function. I suppose it is very similar, if not identical, to 2.7: https://docs.python.org/2.7/library/string.html#string.replace -- components: Distutils messages: 230601 nosy: dstufft, eric.araujo, housetier priority: normal severity: normal status: open title: string replace() not documented type: enhancement versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22792 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
Georg Brandl added the comment: Attributes from the metaclass have always been excluded from the dir() of a class. Be that as it may, I think it is wrong. I can understand excluding methods of the metaclass, but __qualname__ (and friends) are only defined in the metaclass because they are properties and not __dict__ members, but they are regular attributes of the class, not of the metaclass. E.g. why is __module__ in there and not __qualname__? Both are determined dynamically at class creation time. The answer is that it's an implementation detail: there is no tp_module (or ht_module) member in the PyHeapTypeObject struct to store it, so it's stored in __dict__, while __qualname__ is stored in a struct member. -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22790] some class attributes missing from dir(Class)
Georg Brandl added the comment: BTW, the same implementation detail means that you can ask an instance for its class' __module__, but not the __name__. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22790 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22792] string replace() not documented
eryksun added the comment: Follow the String Methods link at the top of the string module documentation. Or use this link: https://docs.python.org/3.4/library/stdtypes.html#str.replace See also help(str.replace) and help(str) in the interactive shell. -- assignee: - docs@python components: +Documentation -Distutils nosy: +docs@python, eryksun ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22792 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com