Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
Veek M wrote: > I was reading the wiki on 'Call stack' because I wanted to understand > what a traceback object was. My C/C++ isn't good enough to deal with > raw python source since I have no background in CS. Also, you just > can't dive into the python src - it takes a good deal of reading and >

Re: IndexError: list index out of range

2016-12-13 Thread Peter Otten
Elnaz wrote: > hi > i am begginer in python. I have written a code and given this error: > IndexError: list index out of range > > In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block > and every 8-block is n. so n=0:7;(h=int(n/4)) I want to rotate 0 to 7 bits > for 2 bits: 0

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Marko Rauhamaa
Veek M : > https://en.wikipedia.org/wiki/Call_stack > > 'Programming languages that support nested subroutines also have a field > in the call frame that points to the stack frame of the latest > activation of the procedure that most closely encapsulates the callee, > i.e. the immediate scope o

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
http://web.archive.org/web/20111030134120/http://www.sidhe.org/~dan/blog/archives/000211.html (great tail recursion article - best i've seen! SO doesn't really explain it unless you already knew it to begin with, but here's the link:http://stackoverflow.com/questions/310974/what-is-tail-call-opti

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Antoon Pardon
Op 13-12-16 om 08:13 schreef Veek M: > 4. When you call a nested function (decorator), it generally returns a > wrapper function but I thought he was just returning a reference to a > function object but obviously since it can see it's environment, how is > the stack being setup? Here you are n

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
Marko Rauhamaa wrote: > Veek M : > >> https://en.wikipedia.org/wiki/Call_stack >> >> 'Programming languages that support nested subroutines also have a >> field in the call frame that points to the stack frame of the latest >> activation of the procedure that most closely encapsulates the >> call

Re: Running python from pty without prompt

2016-12-13 Thread Samuel Williams
Michael, yes. FYI, I found out why this works. Pressing Ctrl-D flushes the input buffer. If you do this on an empty line, it causes read(...) to return 0 which Ruby considers end of input for the script, but the pipe is not closed. -- https://mail.python.org/mailman/listinfo/python-list

asyncio question

2016-12-13 Thread Frank Millman
Hi all I had a problem with asyncio - not a programming problem, but one with organising my code to achieve a given result. I have come up with a solution, but thought I would mention it here to see if there is a better approach. I am using asyncio.start_server() to run a simple HTTP server

Re: Running python from pty without prompt

2016-12-13 Thread Michael Torrie
On 12/13/2016 05:39 AM, Samuel Williams wrote: > Michael, yes. > > FYI, I found out why this works. Pressing Ctrl-D flushes the input > buffer. If you do this on an empty line, it causes read(...) to return > 0 which Ruby considers end of input for the script, but the pipe is > not closed. Curren

Re: asyncio question

2016-12-13 Thread Ian Kelly
On Tue, Dec 13, 2016 at 6:15 AM, Frank Millman wrote: > The client uses AJAX to send messages to the server. It sends the message > and continues processing, while a background task waits for the response and > handles it appropriately. As a result, the client can send a second message > before re

Splitting text into lines

2016-12-13 Thread George Trojan - NOAA Federal
I have files containing ASCII text with line s separated by '\r\r\n'. Example: $ od -c FTAK31_PANC_131140.1481629265635 000 F T A K 3 1 P A N C 1 3 1 1 020 4 0 \r \r \n T A F A B E \r \r \n T A 040 F \r \r \n P A

Re: Splitting text into lines

2016-12-13 Thread Thomas Nyberg
On 12/13/2016 08:45 AM, George Trojan - NOAA Federal wrote: Ideally I'd like to have code that handles both '\r\r\n' and '\n' as the split character. George Are repeated newlines/carriage returns significant at all? What about just using re and just replacing any repeated instances of '\r' or

Re: Splitting text into lines

2016-12-13 Thread Peter Otten
George Trojan - NOAA Federal wrote: > I have files containing ASCII text with line s separated by '\r\r\n'. > but it looks cumbersome. I Python2.x I stripped '\r' before passing the > string to split(): > open('FTAK31_PANC_131140.1481629265635').read().replace('\r', '') > 'FTAK31 PANC 13114

Re: Running python from pty without prompt

2016-12-13 Thread Michael Torrie
On 12/13/2016 09:01 AM, Michael Torrie wrote: > On 12/13/2016 05:39 AM, Samuel Williams wrote: >> Michael, yes. >> >> FYI, I found out why this works. Pressing Ctrl-D flushes the input >> buffer. If you do this on an empty line, it causes read(...) to return >> 0 which Ruby considers end of input f

Re: Splitting text into lines

2016-12-13 Thread George Trojan - NOAA Federal
> > Are repeated newlines/carriage returns significant at all? What about > just using re and just replacing any repeated instances of '\r' or '\n' > with '\n'? I.e. something like > >>> # the_string is your file all read in > >>> import re > >>> re.sub("[\r\n]+", "\n", the_string) > and then co

Re: Splitting text into lines

2016-12-13 Thread George Trojan - NOAA Federal
> > Tell Python to keep the newline chars as seen with > open(filename, newline="") > For example: > >>> > * open("odd-newlines.txt", "rb").read() * > b'alpha\nbeta\r\r\ngamma\r\r\ndelta\n' > >>> > * open("odd-newlines.txt", "r", newline="").read().replace("\r", * > "").splitlines() > ['alpha', 'be

Re: Splitting text into lines

2016-12-13 Thread Random832
On Tue, Dec 13, 2016, at 12:25, George Trojan - NOAA Federal wrote: > > > > Are repeated newlines/carriage returns significant at all? What about > > just using re and just replacing any repeated instances of '\r' or '\n' > > with '\n'? I.e. something like > > >>> # the_string is your file all rea

Re: Running python from pty without prompt

2016-12-13 Thread Random832
On Tue, Dec 13, 2016, at 11:01, Michael Torrie wrote: > On 12/13/2016 05:39 AM, Samuel Williams wrote: > > Michael, yes. > > > > FYI, I found out why this works. Pressing Ctrl-D flushes the input > > buffer. If you do this on an empty line, it causes read(...) to return > > 0 which Ruby considers

Name mangling vs qualified access to class attributes

2016-12-13 Thread paolieri
The official Python tutorial at https://docs.python.org/3/tutorial/classes.html#private-variables says that "name mangling is helpful for letting subclasses override methods without breaking intraclass method calls" and makes an interesting example: class Mapping: def __init__(self, iterabl

Install Problem

2016-12-13 Thread Rhesa Browning
I have been trying to install Python 3.5.2 onto my computer. I have installed and uninstalled and resinstalled several times. Every time I get an error message saying that the python35.dll doesn't exist on my computer so it can't open Python. How can this problem be fixed? rbrowni...@mmm.c

Re: Install Problem

2016-12-13 Thread John Gordon
In Rhesa Browning writes: >I have been trying to install Python 3.5.2 onto my computer. I have >installed and uninstalled and resinstalled several times. Every time I >get an error message saying that the python35.dll doesn't exist on my >computer so it can't open Python. How can this proble

RE: Re: Install Problem

2016-12-13 Thread Rhesa Browning
It occurs when I am trying to open up a python program. I am running windows 7. -Original Message- From: Python-list [mailto:python-list-bounces+rbrowning1=mmm@python.org] On Behalf Of John Gordon Sent: Tuesday, December 13, 2016 2:52 PM To: python-list@python.org Subject: [EXTERNAL]

Re: Install Problem

2016-12-13 Thread eryk sun
On Tue, Dec 13, 2016 at 8:37 PM, Rhesa Browning wrote: > I have been trying to install Python 3.5.2 onto my computer. I have > installed and > uninstalled and resinstalled several times. Every time I get an error message > saying that the python35.dll doesn't exist on my computer so it can't op

Re: Running python from pty without prompt

2016-12-13 Thread Michael Torrie
On 12/13/2016 10:48 AM, Random832 wrote: > The problem is there's currently no way to differentiate "interactive > mode" from "script run on a tty". > > You can get similar behavior with python -c "import > sys;exec(sys.stdin.read())" Are you sure? I can pipe scripts into Python and they run fine

Re: Name mangling vs qualified access to class attributes

2016-12-13 Thread Cameron Simpson
On 13Dec2016 12:27, paoli...@gmail.com wrote: The official Python tutorial at https://docs.python.org/3/tutorial/classes.html#private-variables says that "name mangling is helpful for letting subclasses override methods without breaking intraclass method calls" and makes an interesting example

Re: Running python from pty without prompt

2016-12-13 Thread Random832
On Tue, Dec 13, 2016, at 17:09, Michael Torrie wrote: > On 12/13/2016 10:48 AM, Random832 wrote: > > The problem is there's currently no way to differentiate "interactive > > mode" from "script run on a tty". > > > > You can get similar behavior with python -c "import > > sys;exec(sys.stdin.read()

Re: Splitting text into lines

2016-12-13 Thread Steve D'Aprano
On Wed, 14 Dec 2016 03:45 am, George Trojan - NOAA Federal wrote: > I have files containing ASCII text with line s separated by '\r\r\n'. > Example: > > $ od -c FTAK31_PANC_131140.1481629265635 > 000 F T A K 3 1 P A N C 1 3 1 1 > 020 4 0 \r \r \n

Re: Running python from pty without prompt

2016-12-13 Thread Steve D'Aprano
On Wed, 14 Dec 2016 09:24 am, Random832 wrote: > On Tue, Dec 13, 2016, at 17:09, Michael Torrie wrote: >> On 12/13/2016 10:48 AM, Random832 wrote: >> > The problem is there's currently no way to differentiate "interactive >> > mode" from "script run on a tty". >> > >> > You can get similar behavi

Re: Running python from pty without prompt

2016-12-13 Thread Steve D'Aprano
On Wed, 14 Dec 2016 04:48 am, Random832 wrote: > On Tue, Dec 13, 2016, at 11:01, Michael Torrie wrote: >> On 12/13/2016 05:39 AM, Samuel Williams wrote: >> > Michael, yes. >> > >> > FYI, I found out why this works. Pressing Ctrl-D flushes the input >> > buffer. If you do this on an empty line, it

Re: Running python from pty without prompt

2016-12-13 Thread Michael Torrie
On 12/13/2016 05:10 PM, Steve D'Aprano wrote: > Can you show a simple demonstration of what you are doing? I think they want to run Python, perhaps remotely via ssh, and feed it both a script and input over standard-in (though a tty comes into this somehow and I'm not clear on that). Apparently i

Re: Running python from pty without prompt

2016-12-13 Thread Ben Finney
Steve D'Aprano writes: > I thought that with the exception of scripts run from cron, any time > you run a script *or* in interactive mode, there is an associated tty. > Am I wrong? Any daemon will, by definition, have no controlling terminal. Other processes can choose to detach themselves from

OT - "Soft" ESC key on the new MacBook Pro

2016-12-13 Thread Skip Montanaro
I know this isn't a Python-specific question, but i got zero useful responses from the help-gnu-emacs list for some reason. I think this expression should not evaluate to the empty set: set(python_programmers) & set(emacs_users) & set(new_macbookpro_owners) Hopefully there are a few people out th

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-13 Thread Michael Torrie
On 12/13/2016 06:06 PM, Skip Montanaro wrote: > So, for those of you who've tried it, does the lack of a physical ESC key > create problems? If there were problems with it I imagine ViM users would probably be more inconvenienced than Emacs users. I haven't heard anything about people's real-worl

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-13 Thread Paul Rubin
Skip Montanaro writes: > Does the lack of a physical ESC key create problems for people, especially > Emacs users? Not a Mac user and I rarely use ESC instead of ALT while editing with Emacs on a local computer, but when editing remotely I do have to use ESC because the Gnome terminal emulator st

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-13 Thread Gregory Ewing
Paul Rubin wrote: First it was the hipster Mac users with the Beatnik black berets and turtlenecks, and now this. Once you're in the clutches of Apple, there is no Escape. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Is there a way to insert hooks into a native dictionary type to see when a query arrives and what's looked up?

2016-12-13 Thread Veek M
I know that with user classes one can define getattr, setattr to handle dictionary lookup. Is there a way to hook into the native dict() type and see in real time what's being queried. I wanted to check if when one does: x.sin() if the x.__dict__ was queried or if the Foo.__dict__ was queried.

Re: asyncio question

2016-12-13 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzid=vdczAH18mHKaL7ryvDUB=7_y-JVUrTkRZ=gkz66p...@mail.gmail.com... On Tue, Dec 13, 2016 at 6:15 AM, Frank Millman wrote: > The client uses AJAX to send messages to the server. It sends the > message > and continues processing, while a background task waits

Re: Is there a way to insert hooks into a native dictionary type to see when a query arrives and what's looked up?

2016-12-13 Thread Chris Angelico
On Wed, Dec 14, 2016 at 5:11 PM, Veek M wrote: > I know that with user classes one can define getattr, setattr to handle > dictionary lookup. Is there a way to hook into the native dict() type > and see in real time what's being queried. > > I wanted to check if when one does: > > x.sin() > > if t

Re: IndexError: list index out of range

2016-12-13 Thread Elnaz
On Tuesday, December 13, 2016 at 12:45:49 PM UTC+3:30, Peter Otten wrote: > Elnaz wrote: > > > hi > > i am begginer in python. I have written a code and given this error: > > IndexError: list index out of range > > > > In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block > >