Re: [Tutor] FrozenDict

2015-10-08 Thread eryksun
On 10/8/15, Steven D'Aprano wrote: > > That's one solution, but it is certainly possible for the class to be > its own iterator, in which case it needs to follow two rules: > > (1) self.__next__() needs to return the next value, or raise > StopIteration; > > (2) self.__iter__() needs to return sel

Re: [Tutor] Can someone explain this to me please

2015-08-22 Thread eryksun
On Fri, Aug 21, 2015 at 1:04 PM, Jon Paris wrote: > > import sys > x = sys.maxsize > print ("Max size is: ", x) > y = (x + 1) > print ("y is", type(y), "with a value of", y) > > Produces this result: > > Max size is: 9223372036854775807 > y is with a value of 9223372036854775808 > > I was expect

Re: [Tutor] for loop for long numbers

2015-08-03 Thread eryksun
On Mon, Aug 3, 2015 at 8:50 PM, Steven D'Aprano wrote: > If you have a 64-bit operating system, you can use a 64-bit version of > Python, and the limit will be something like 2**63 - 1 or so. I can't > test this myself, as I have a 32-bit system like you. A notable exception to the above claim is

Re: [Tutor] Windows "feature" I don't understand

2015-08-03 Thread eryksun
On Sun, Aug 2, 2015 at 9:14 PM, Clayton Kirkwood wrote: > get into the innards much. I ran into a problem in my program, which we have > been discussing, which is windows-caused. I originally set my directory in > my code to /users/Clayton/Pictures by memory that that was the name of the > direct

Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread eryksun
On Mon, May 4, 2015 at 2:46 AM, Chris Warrick wrote: > Python 3.0–3.2 do not support the u'' notation for Unicode strings, it > was restored in Python 3.3 to make it easier to write code compatible > with 2.x and 3.x Whoever restored this forgot about raw literals: >>> ur'abc' File "",

Re: [Tutor] subprocess.Popen(..., cwd) and UNC paths

2015-05-01 Thread eryksun
On Fri, May 1, 2015 at 8:03 AM, Albert-Jan Roskam wrote: > I used a str for cmd because I found it more readable that way. I could do > cmd.split(). Don't use cmd.split(). That just splits on whitespace without respecting how the shell tokenizes the command. Use shlex.split(cmd) instead. > So o

Re: [Tutor] subprocess.Popen(..., cwd) and UNC paths

2015-04-29 Thread eryksun
On Wed, Apr 29, 2015 at 8:28 PM, eryksun wrote: > After disabling the check, my previous example should work fine: Except it doesn't accept paths relative to a UNC working directory: (test) \\127.0.0.1\C$>cd Temp The system cannot find the path specified. And the cd command

Re: [Tutor] subprocess.Popen(..., cwd) and UNC paths

2015-04-29 Thread eryksun
On Wed, Apr 29, 2015 at 7:48 PM, eryksun wrote: > cmd.exe was developed for OS/2 (1987) to replace COMMAND.COM (1981). Actually, I stand corrected about the reason being cmd's 1980s crustiness. Per [KB156276][1] this check was added to NT 4.0 (1996) to address a vaguely described problem

Re: [Tutor] subprocess.Popen(..., cwd) and UNC paths

2015-04-29 Thread eryksun
On Wed, Apr 29, 2015 at 7:08 PM, Alan Gauld wrote: > On 30/04/15 00:12, eryksun wrote: > >> the working directory, but the cmd.exe shell (being a crusty relic of >> the 1980s) does not. > > Actually cmd.exe is fine with UNC paths. It's only when you > combine them

Re: [Tutor] subprocess.Popen(..., cwd) and UNC paths

2015-04-29 Thread eryksun
On Wed, Apr 29, 2015 at 11:54 AM, Albert-Jan Roskam wrote: > Hmmm, that sounds pretty convincing indeed (makes it even stranger that CD > works the way it works). > I believe it threw a WindowsError, indicating that the file(s) could not be > found, because the dir was > not changed. I actually

Re: [Tutor] sig no matter what

2015-04-25 Thread eryksun
On Fri, Apr 24, 2015 at 10:46 PM, Jim Mooney wrote: > The docs don't mention that case is immaterial for aliases, when it usually > matters in Python. Section 7.2.3: Notice that spelling alternatives that only differ in case or use a hyphen instead of an underscore are also valid aliases

Re: [Tutor] sig no matter what

2015-04-24 Thread eryksun
On Fri, Apr 24, 2015 at 6:43 PM, Jim Mooney wrote: > It looks like sig works for any dash, underline combination, and is ignored > if there is no BOM: See 7.2.3 (aliases) and 7.2.7 (utf_8_sig) in the codecs documentation. https://docs.python.org/3/library/codecs.html

Re: [Tutor] bin to dec conversion puzzlement

2015-04-20 Thread eryksun
On Mon, Apr 20, 2015 at 11:21 AM, Alan Gauld wrote: >> >> B = '11011101' >> I = 0 >> while B: >> I = I * 2 + int(B[0]) >> B = B[1:] > >> Both methods work but I just can't see how the first one does. > > The key is that the result gets multiplied by 2 each time > so for an N bit number t

Re: [Tutor] How to pass varying number of arguments to functions called by a dictionary?

2015-02-11 Thread eryksun
On Wed, Feb 11, 2015 at 7:27 AM, boB Stepp wrote: > > pass_args = {'a': (x1, x2, x3), 'b': (y1, y2), 'c': (z)} > call_fcn[key_letter](key_letter) > > But ran into the syntax error that I was giving one argument when > (possibly) multiple arguments are expected. Do it like this: pass_args = {

Re: [Tutor] Wondering if there is a print in location command for terminal?

2015-02-10 Thread eryksun
On Tue, Feb 10, 2015 at 3:02 AM, Alan Gauld wrote: > msvcrt wraps the Microsoft Vis C Runtime functions which don't > include positional commands. > > Conio was a DOS library developed by the compiler makers as a way to access > the BIOS calls and has a gotoXY() and similar functions. It first app

Re: [Tutor] Wondering if there is a print in location command for terminal?

2015-02-09 Thread eryksun
On Mon, Feb 9, 2015 at 6:40 PM, Alan Gauld wrote: > > Yes curses is probably the best fit here. It doesn't work > so well on Windows but on Linux/MacOS it does a good job. curses for Windows (based on PDCurses): http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses > There are some other library pac

Re: [Tutor] multiprocessing question

2014-11-28 Thread eryksun
On Fri, Nov 28, 2014 at 3:24 AM, Cameron Simpson wrote: > > With multiprocessing they're completely separate (distinct memory spaces); > data > must be passed from one to the other, and there's a cost for that. Single-machine IPC can use shared memory, not just message passing via pipes and sock

Re: [Tutor] multiprocessing question

2014-11-28 Thread eryksun
On Thu, Nov 27, 2014 at 2:40 PM, Albert-Jan Roskam wrote: > >>CsvIter._get_row_lookup should work on a regular file from built-in >>open (not codecs.open), opened in binary mode. I/O on a regular file >>will release the GIL back to the main thread. mmap objects don't do >>this. > > Will io.open al

Re: [Tutor] "Philosophical" question about string slicing from end of a string

2014-11-24 Thread eryksun
On Mon, Nov 24, 2014 at 1:33 PM, Zachary Ware wrote: > Also note that there's no way to get the last member with a negative > second index. Also note that, given a -1 step, there's no way to get the first member with a non-negative second index. >>> s[-1:0:-1] '987654321' It requires a

Re: [Tutor] multiprocessing question

2014-11-24 Thread eryksun
On Sun, Nov 23, 2014 at 7:20 PM, Cameron Simpson wrote: > > A remark about the create_lookup() function on pastebin: you go: > > record_start += len(line) > > This presumes that a single text character on a line consumes a single byte > or memory or file disc space. However, your data file is utf

Re: [Tutor] don't understand iteration

2014-11-11 Thread eryksun
On Tue, Nov 11, 2014 at 4:52 AM, Alan Gauld wrote: > On 11/11/14 04:45, Clayton Kirkwood wrote: > *list(range(1,6)) >> >>File "", line 1 >> SyntaxError: can use starred expression only as assignment target > > list() is a function. You cannot unpack a function. > > Also the * operator nee

Re: [Tutor] eval use (directly by interpreter vs with in a script)

2014-11-02 Thread eryksun
On Sun, Nov 2, 2014 at 3:07 PM, Peter Otten <__pete...@web.de> wrote: > Inside a function there is no direct way to get access to the local > namespace used by exec(). Indeed, exec() can't create new function locals, or even update the values of existing function locals. Another option for indire

Re: [Tutor] User Input with Multiple Lines

2014-10-26 Thread eryksun
On Sun, Oct 26, 2014 at 3:25 PM, Malik Brahimi wrote: > So I am working with input that is pasted from a PDF file, and I was > wondering if there is any way I can do so without the program terminating > abruptly because of the newlines. input() and raw_input() grab a single line of text. The rest

Re: [Tutor] Passing Data to .DLL

2014-10-22 Thread eryksun
On Wed, Oct 22, 2014 at 6:05 PM, eryksun wrote: > from_buffer_copy is similar, accept instead of sharing the buffer That should be ex-cept (conjunction for an exception clause), not ac-cept (verb, to receive). I missed that in my initial proofread. It takes a while to clear my mental buf

Re: [Tutor] Passing Data to .DLL

2014-10-22 Thread eryksun
On Wed, Oct 22, 2014 at 3:50 PM, Wilson, Pete wrote: > I don't understand the line > rx_buf = (c_uint8 * rx_buf_size).from_buffer_copy(string_buf) A buffer is a block of memory used to pass data between functions, processes, or systems. Specifically its use as a 'buffer' comes from using a block

Re: [Tutor] Passing Data to .DLL

2014-10-22 Thread eryksun
On Tue, Oct 21, 2014 at 7:04 PM, Wilson, Pete wrote: > > ProcessIncomingSerialData_t = CFUNCTYPE(None, POINTER(c_uint8), c_uint16) > process_incoming_serial_data = pt_dll.ProcessIncomingSerialData > process_incoming_serial_data.argtypes = [ProcessIncomingSerialData_t] ProcessIncomingSerialData ta

Re: [Tutor] Convert Qstring to string in windows

2014-10-17 Thread eryksun
On Thu, Oct 16, 2014 at 10:21 AM, C@rlos wrote: > in linux i do for this way: > pythonstringtext=qstringtext.text().toUtf8.data() > and it return a python string correctly. pythonstringtext is a byte string that has to be decoded as UTF-8. Here's the 'mojibake' result when it gets decoded as UTF-

Re: [Tutor] Registering callbacks and .DLL

2014-10-17 Thread eryksun
On Thu, Oct 16, 2014 at 6:35 PM, Wilson, Pete wrote: > > The .DLL was written in C++ is working with C++ apps calling it. ctypes doesn't support the platform C++ ABI (I don't think the VC++ ABI is even stable), classes, STL containers, or exceptions [*]. It isn't "cpptypes". To work with ctypes,

Re: [Tutor] A couple newbie questions about Python

2014-06-12 Thread eryksun
On Thu, Jun 12, 2014 at 1:27 AM, Alex Kleider wrote: > On 2014-06-11 20:08, Dave Angel wrote: > >> I learned programming in 1967 with Fortran, and McCracken spent a >> chapter warning about that same thing. Probably everything he >> warned about still applies to Python and modern computers. > > A

Re: [Tutor] Help with Guess the number script

2014-03-10 Thread eryksun
On Mon, Mar 10, 2014 at 5:29 AM, Mark Lawrence wrote: > > As a newbie don't worry about it (yet). Personally I think it's plain daft > to put such advanced language topics on a tutor mailing list. Different strokes for different folks. I like to tinker with and disassemble things as I'm learning

Re: [Tutor] Help with Guess the number script

2014-03-09 Thread eryksun
> On Mar 8, 2014, at 7:29 AM, eryksun wrote: >> >>not not (guess < 1 or guess > 100) > > Why a not not? Wouldn’t that just be saying do this because the > second not is undoing the first? In boolean algebra, `not (A or B)` is equivalent to `not A and not

Re: [Tutor] Help with Guess the number script

2014-03-08 Thread eryksun
On Sat, Mar 8, 2014 at 1:44 PM, Scott dunning wrote: >> if 1 > guess > 100: >> > OH! I see what you're saying, ignore my last post. Yes that looks > cleaner. Please read section 6.9 of the language reference, which defines Python comparison expressions. http://docs.python.org/3/reference/expre

Re: [Tutor] Help with Guess the number script

2014-03-08 Thread eryksun
On Sat, Mar 8, 2014 at 8:36 AM, Dave Angel wrote: > Mark Lawrence Wrote in message: >> On 08/03/2014 01:23, Scott W Dunning wrote: >> >>> def print_hints(secret, guess): >>> if guess < 1 or guess > 100: >> >> Only now do I feel that it's time to point out that the above line would >> probab

Re: [Tutor] c++ on python

2014-03-07 Thread eryksun
On Fri, Mar 7, 2014 at 9:29 AM, Gabriele Brambilla wrote: > > in the next days I will receive a c++ code that I would like to run in > python (http://docs.python.org/2/extending/index.html). > It should be self consistent (no extraroutines). > I want to be ready to use it... Has someone some C++

Re: [Tutor] How to determine which function code is being called from

2014-03-07 Thread eryksun
On Fri, Mar 7, 2014 at 6:45 AM, Danny Yoo wrote: > > Although many of the recommendations have been discouraging the stack > inspection approach, even stack inspection might be appropriate, > though it's certainly not a technique for beginners. Stack inspection is really intended for debugging or

Re: [Tutor] reg: How to import dll in python

2014-03-05 Thread eryksun
On Wed, Mar 5, 2014 at 7:49 AM, Shweta Kaushik wrote: > > Please find code used to create dll: I hardly ever use C++, so C++ gurus feel free to correct any errors here. I just wanted a basic C API to work with ctypes -- since that's the Python aspect of this question. I've also only targeted Micr

Re: [Tutor] When to use multiprocessing Managers?

2014-03-03 Thread eryksun
On Mon, Mar 3, 2014 at 6:45 AM, James Chapman wrote: > Thanks for the explanation. > > Is there any reason or case you can think of where on a single system > you would use the manager (proxied) queue over the multiprocessing > (piped) queue? Not really. But a manager also lets you share lists, d

Re: [Tutor] When to use multiprocessing Managers?

2014-03-01 Thread eryksun
On Fri, Feb 28, 2014 at 6:31 AM, James Chapman wrote: > > log_Q = multiprocessing.Queue() This is a Queue from multiprocessing.queues. It uses system resources (e.g. a semaphore for the queue capacity) that can be shared with processes on the same machine. A value `put` in a queue.Queue is avail

Re: [Tutor] Installing numpy on Ubuntu

2014-02-27 Thread eryksun
On Thu, Feb 27, 2014 at 5:11 PM, Danny Yoo wrote: > You mentioned you're using Ubuntu 12.04. But the version of Python 3 > in that Ubuntu is Python 3.1: > > http://packages.ubuntu.com/lucid/python/python3 12.04 (precise), not 10.04 (lucid). So the python3-numpy package targets Python 3.2, bu

Re: [Tutor] Installing numpy on Ubuntu

2014-02-27 Thread eryksun
On Thu, Feb 27, 2014 at 4:18 PM, Pierre Dagenais wrote: > I've installed numpy on Ubuntu 12.04 with > sudo apt-get install python3-numpy. > Everything seems to go OK Probably you installed NumPy for python3.2: http://packages.ubuntu.com/precise/python3-numpy > Python 3.3.3 (default, Dec

Re: [Tutor] calling global in funtions.

2014-02-26 Thread eryksun
On Wed, Feb 26, 2014 at 8:45 AM, Steven D'Aprano wrote: >> :4: SyntaxWarning: name 'a' is assigned to before global declaration > > This is just a warning. It is STRONGLY RECOMMENDED that you put the > global declaration at the top of the function, but it is not compulsary. > If you put it somewhe

Re: [Tutor] subprocess.call list vs. str argument

2014-02-26 Thread eryksun
On Wed, Feb 26, 2014 at 3:50 AM, Albert-Jan Roskam wrote: > On Tue, Feb 25, 2014 at 4:54 PM, Dave Angel wrote: >> CreateProcess has its own design bobbles as well. For >> example, if you forget to put quotes around the program >> name, it will happily try to add ".exe" to *multiple* >> places in

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread eryksun
On Tue, Feb 25, 2014 at 4:54 PM, Dave Angel wrote: > CreateProcess has its own design bobbles as well. For example, if > you forget to put quotes around the program name, it will > happily try to add ".exe" to *multiple* places in the hopes that > one of them will work. > > Adding a file c:\prog

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread eryksun
On Tue, Feb 25, 2014 at 2:52 PM, Albert-Jan Roskam wrote: > Here is why I used "shell=True" before. Is it related to the > file paths? > > cmd = (r'sphinx-apidoc ' >r'-f -F ' >r'-H "%(title)s" ' >r'-A "%(author)s" ' >r'-V "%(version)s" ' >

Re: [Tutor] Regarding Exceptions

2014-02-21 Thread eryksun
On Fri, Feb 21, 2014 at 8:50 PM, Steven D'Aprano wrote: > The history of __builtins__ with an S is quite old. It's used for > performance reasons, and originally it was supposed to be used for > sandboxing Python, but that turned out to not work. So although it still > exists even in Python 3, it'

Re: [Tutor] Regarding Exceptions

2014-02-21 Thread eryksun
On Fri, Feb 21, 2014 at 12:48 PM, wesley chun wrote: > in reality, built-ins are part of a magical module called __builtins__ > that's "automagically" imported for you so that you never have to do it > yourself. check this out: > __builtins__.Exception > > > you can also find out what all th

Re: [Tutor] from command prompt use interactive python and running script together

2014-02-21 Thread eryksun
On Fri, Feb 21, 2014 at 9:20 AM, Gabriele Brambilla wrote: > > Is possible on python to running scripts from the command prompt (I'm using > python on windows) and in the end saving all the variables and continue the > analysis in the interactive mode? (the one that you activate typing python > in

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 6:59 PM, "André Walker-Loud " wrote: > > Also, since you are chiming in, do you have an opinion in general about > which approach you prefer? The string hacking vs class method (for lack > of better way to describe them)? I've never used iminuit before. I'd ask on a suppo

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 2:56 PM, "André Walker-Loud " wrote: > > I also happened to get the string-hack to work (which requires > using global variables). Functions load unassigned names from the global/builtins scopes, so there's no need to declare the g* variables global in chisq_mn. Also, impl

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 7:33 AM, Oscar Benjamin wrote: > I don't really understand why it works that way though. > Looking here > >http://iminuit.github.io/iminuit/api.html#function-sig-label This API is unusual, but co_argcount and co_varnames should be available and defined as per the spec:

Re: [Tutor] Python .decode issue

2014-02-11 Thread eryksun
On Tue, Feb 11, 2014 at 3:42 AM, Peter Otten <__pete...@web.de> wrote: > > Unfortunately the bytes --> bytes conversion codecs in Python 2 have no > convenient analog in Python 3 yet. > > This will change in Python 3.4, where you can use > import codecs codecs.decode(b"ff10", "hex") > b'\

Re: [Tutor] catching the row that raises IntegrityError in sqlite

2014-02-09 Thread eryksun
On Sun, Feb 9, 2014 at 5:20 AM, Peter Otten <__pete...@web.de> wrote: > > The idea here is to wrap the iterable of records to be inserted in the Iter > class which keeps track of the last accessed row. You could also use a parameters iterator, e.g. `it = iter(to_db)`. Then for an IntegrityError, l

Re: [Tutor] good django book?

2014-02-07 Thread eryksun
On Fri, Feb 7, 2014 at 8:02 PM, Alex Kleider wrote: > It might be worth pointing out that the version of django that comes with > Debian/Ubuntu is > Version: 1.3.1-4ubuntu1 > so worrying about having a text that describes 1.6 vs 1.4 may not be all > that important. > > Comments? Debian stable cur

Re: [Tutor] sys.path.append import python3 not working

2014-02-05 Thread eryksun
On Wed, Feb 5, 2014 at 6:55 AM, Ian D wrote: > The network dictates that it is the only way I can really do it as I cannot > edit any files directly. I have to append the path on the fly If you can modify your profile, then I'd expect you can permanently set PYTHONPATH for the current user. setx.

Re: [Tutor] my modules idle doesn't list functions python3.3

2014-02-05 Thread eryksun
On Wed, Feb 5, 2014 at 6:53 AM, Ian D wrote: > > But if I use Python 3.3 > It does not display the functions using autocomplete Maybe IDLE's AutoComplete extension is disabled. The configuration is in Lib\idlelib\config-extensions.def, with the following defaults: [AutoComplete] enable=1

Re: [Tutor] Best version for novice

2014-02-01 Thread eryksun
On Sat, Feb 1, 2014 at 8:20 PM, Steven D'Aprano wrote: > > I'm afraid that I have no idea what you are talking about here, Python > doesn't accept a -n argument: -n is an IDLE option: If IDLE is started with the -n command line switch it will run in a single process and will not create t

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread eryksun
On Fri, Jan 31, 2014 at 6:31 AM, James Chapman wrote: > try: > while self.attribute: > time.sleep(1) > except KeyboardInterrupt: > ... > > My unit test could then set the attribute. However I'd still have the > problem of how I get from the unit test line that fires up the method t

Re: [Tutor] getUncPath(mappedDrive)

2014-01-30 Thread eryksun
On Thu, Jan 30, 2014 at 8:13 AM, danz wrote: > I apologize to all, but my above code won't work with paths that have > embedded spaces. It also turns out that the "net use" command inserts a > carriage-return/line-feed between the Path and Network fields when the last > character position of the

Re: [Tutor] Python shell wont open IDLE or an exisiting .py files

2014-01-29 Thread eryksun
On Wed, Jan 29, 2014 at 11:16 PM, Ben Finney wrote: > Terry Reedy writes: > >> This I do not. What is 'Python GUI'? What is 'Python Shell'? > > Those are (part of) the names of menu entries created by the Python > installer for MS Windows. I am not sure exactly what programs they > invoke. The a

Re: [Tutor] help with data insert into Access table

2014-01-29 Thread eryksun
On Wed, Jan 29, 2014 at 3:53 PM, Keith Winston wrote: > I had the impression that Peter was employing tuples because, > as an immutable type, it couldn't inadvertently/inauspiciously > be changed by a user Per footnote 5 of PEP 249, the parameters need to be in a type that supports __getitem__ (s

Re: [Tutor] subprocess.Popen help

2014-01-28 Thread eryksun
On Tue, Jan 28, 2014 at 2:52 PM, leam hall wrote: > Python tutorial for 2.6 (using 2.4 -- don't ask), first code blurb under > 17.1.1 > > http://docs.python.org/2.6/library/subprocess.html?highlight=subprocess#subprocess.Popen > > How would you make an ssh to another box put data back in "p"? The

Re: [Tutor] Coordinates TK and Turtle

2014-01-28 Thread eryksun
On Tue, Jan 28, 2014 at 4:48 AM, Ian D wrote: > > I have some weird results when I run my code which is meant to display a > canvas and a turtle and some text with the turtles coordinates. > > Basically the turtle coordinates do not seem to correspond with the TK > create_text coordinates. > > t1.

Re: [Tutor] When is = a copy and when is it an alias

2014-01-27 Thread eryksun
On Mon, Jan 27, 2014 at 9:07 AM, Mark Lawrence wrote: > On 27/01/2014 09:53, spir wrote: >> >> Note: your example is strongly obscured by using weird and rare features >> that don't bring any helpful point to the actual problematic concepts >> you apparently want to deal with. >> > > Nothing weird

Re: [Tutor] When is = a copy and when is it an alias

2014-01-27 Thread eryksun
On Mon, Jan 27, 2014 at 2:01 PM, Danny Yoo wrote: > And variable binding itself can even have a slightly > different meaning, depending on whether the surrounding context is a > function definition or not, establishing a local or global variable > binding. Whew! Name binding is local unless you

Re: [Tutor] code works in windows command but not ubuntu terminal

2014-01-24 Thread eryksun
On Fri, Jan 24, 2014 at 8:38 PM, Steven D'Aprano wrote: > > However, there's more to it than this. For starters, you need to decide > on the exact behaviour. Clearly, "file not found" errors should move on > to try the next prefix in the path list. But what about permission > denied errors? Prior

Re: [Tutor] Iterator vs. iterable cheatsheet, was Re: iter class

2014-01-24 Thread eryksun
On Fri, Jan 24, 2014 at 8:50 AM, spir wrote: > > xs is an iterator (__next__ is there), then Python uses it directly, thus > what is the point of __iter__ there? In any case, python must check whether Python doesn't check whether a type is already an iterator. It's simpler to require that iterato

Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 7:43 PM, Steven D'Aprano wrote: > Generators are a kind of function, which are special. You can't inherit > from them: I clarified my sloppy language in a reply. `__iter__` should be a generator function, not a generator. A generator function uses `yield` and `yield from`

Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 2:24 PM, Keith Winston wrote: > On Thu, Jan 23, 2014 at 7:05 AM, eryksun wrote: >> Generally you'll make `__iter__` a generator, so you don't have to >> worry about implementing `__next__`. Also, the built-in function >> `next` was added in

Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 10:50 AM, Keith Winston wrote: > On Thu, Jan 23, 2014 at 7:05 AM, eryksun wrote: >> Generally you'll make `__iter__` a generator, so you don't have to >> worry about implementing `__next__`. Also, the built-in function >> `next` was add

Re: [Tutor] iter class

2014-01-23 Thread eryksun
On Thu, Jan 23, 2014 at 12:53 AM, Keith Winston wrote: >> in Python 3, it should be __next__, not next. > > Ah! That's it! Thanks!!! Generally you'll make `__iter__` a generator, so you don't have to worry about implementing `__next__`. Also, the built-in function `next` was added in 2.6, so you

Re: [Tutor] when is "pythondontwritebytecode" useful?

2014-01-22 Thread eryksun
On Tue, Jan 21, 2014 at 2:44 PM, Albert-Jan Roskam wrote: > > Hmmm, number of OS * number of Python versions = a lot of packages. Isn't > a .zip file easiest? Or maybe msi or wininst*) on Windows and .deb on > Linux (with alien that can easily be converted to e.g. rpm). The egg format is old and

Re: [Tutor] how to send "ctrl+a+c" with python

2014-01-22 Thread eryksun
On Wed, Jan 22, 2014 at 8:49 AM, lei yang wrote: > > I want to use pexpect to send "ctrl+a+c" What's ctrl+a+c? If this is for screen, then I think you mean ctrl+a c: sendcontrol('a') send('c') ___ Tutor maillist - Tutor@python.org To unsubscr

Re: [Tutor] Understanding Classes

2014-01-21 Thread eryksun
On Tue, Jan 21, 2014 at 7:18 AM, Steven D'Aprano wrote: > The same applies to methods, with just one additional bit of magic: when > you call a method like this: > > instance.method(a, b, c) # say > > Python turns it into a function call: > > method(instance, a, b, c) > > [For advanced

Re: [Tutor] How to print certain elements

2014-01-21 Thread eryksun
On Tue, Jan 21, 2014 at 5:18 AM, Alan Gauld wrote: > > for name in X: > if name not in (X[0], X[-1]): >print name > > For the special case of excluding the first and > last names you could use the [:] notation like > this: > > print X[1:-1] > > But that only works where you want *all*

Re: [Tutor] when is "pythondontwritebytecode" useful?

2014-01-20 Thread eryksun
On Mon, Jan 20, 2014 at 5:42 AM, Albert-Jan Roskam wrote: > > When is setting a PYTHONDONTWRITEBYTECODE environment variable useful? Or > set sys.dont_write_bytecode to True? Or start Python with the -B option? > I know what it does > (http://docs.python.org/2/using/cmdline.html#envvar-PYTHONDONTW

Re: [Tutor] Question on os.popen

2014-01-19 Thread eryksun
On Sun, Jan 19, 2014 at 6:36 PM, SM wrote: > > This time it probably ran for a few more iterations than before and stopped > with the same error message. This time it also output the following > messages: > > IOError: [Errno 4] Interrupted system call > Attribute not found in file (tsk_fs_attrlist

Re: [Tutor] Naming variables

2014-01-19 Thread eryksun
On Sun, Jan 19, 2014 at 9:21 AM, spir wrote: > I guess (not sure) python optimises access of dicts used as scopes (also of > object attributes) by interning id-strings and thus beeing able to replace > them by hash values already computed once for interning, or other numeric A string object cache

Re: [Tutor] iterators

2014-01-18 Thread eryksun
On Sat, Jan 18, 2014 at 6:24 PM, Keith Winston wrote: > > I guess it makes sense that iter() returns a type iterator. `iter(obj)` returns `obj.__iter__()` if the method exists and the result is an iterator, i.e. has a `__next__` method. Otherwise if `obj.__getitem__` exists, it returns a generic

Re: [Tutor] iterators

2014-01-18 Thread eryksun
On Sat, Jan 18, 2014 at 4:22 AM, Chris “Kwpolska” Warrick wrote: > For Python 2, use xrange() instead to get an iterator. In Python 3, > range() is already an iterator. `xrange` and 3.x `range` aren't iterators. They're sequences. A sequence implements `__len__` and `__getitem__`, which can be u

Re: [Tutor] Understanding Decorators

2014-01-18 Thread eryksun
On Sat, Jan 18, 2014 at 12:51 PM, Reuben wrote: > > I tried reading information regarding decorators - but not able to get a > good grip around it. > > Kindly point me to some good links along with examples Decorators I: Introduction to Python Decorators http://www.artima.com/weblogs/viewpost.jsp

Re: [Tutor] iterators

2014-01-18 Thread eryksun
On Sat, Jan 18, 2014 at 4:50 AM, Peter Otten <__pete...@web.de> wrote: > > PS: There is an odd difference in the behaviour of list-comps and generator > expressions. The latter swallow Stopiterations which is why the above > myzip() needs the len() test: A comprehension is building a list in a `fo

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-17 Thread eryksun
On Fri, Jan 17, 2014 at 10:32 AM, Steven D'Aprano wrote: > import mockimport > unittestimport > pinger > > > would not be "fine". Screenshot: http://i.imgur.com/wSihI1X.png The following is in a tag, so the whitespace is rendered literally: import mock import unittest import pinger class ---

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-17 Thread eryksun
On Fri, Jan 17, 2014 at 6:23 AM, Steven D'Aprano wrote: > On Fri, Jan 17, 2014 at 09:58:06AM +, James Chapman wrote: > >> import subprocess >> class Pinger(object): > > There is your first SyntaxError, a stray space ahead of the "class" > keyword. The rich text version is correct (and colorf

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-17 Thread eryksun
On Fri, Jan 17, 2014 at 4:58 AM, James Chapman wrote: > import mock > import unittest > import pinger > > class Test_Pinger(unittest.TestCase): > > def test_ping_host_succeeds(self): > pinger = pinger.Pinger() Are you using CPython? That raises an UnboundLocalError. Take a look at the

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-16 Thread eryksun
On Thu, Jan 16, 2014 at 5:32 AM, James Chapman wrote: > > In my unittest I don't want to run the ping command, (It might not be > available on the build system) I merely want to check that a call to > subprocess.Popen is made and that the parameters are what I expect? You can mock `Popen` where i

Re: [Tutor] iPython notebook In [*]: numbering

2014-01-15 Thread eryksun
On Wed, Jan 15, 2014 at 4:55 PM, Steven D'Aprano wrote: > On Wed, Jan 15, 2014 at 01:55:53PM +0100, Christoph Kukulies wrote: >> Am 14.01.2014 15:27, schrieb eryksun: >> >Did you try restarting the kernel and then recalculating the cells? >> > >> > Ker

Re: [Tutor] Problems using odeint

2014-01-15 Thread eryksun
On Wed, Jan 15, 2014 at 1:42 AM, eryksun wrote: > > The trajectory is decaying into the planet. In real life it hits the > surface. Not quite. A radius of 1.4 km is inside the planet, so that's unrealistic from the start. If it starts at the surface of Mars, at around 3,40

Re: [Tutor] Problems using odeint

2014-01-14 Thread eryksun
On Tue, Jan 14, 2014 at 1:40 PM, Grace Roberts wrote: > > -For certain initial conditions the programme displays impossible orbits, > showing the satellite making immediate sharp turns or jumping up and down in > velocity. The exact same code can also end up displaying different graphs > when run

Re: [Tutor] iPython notebook In [*]: numbering

2014-01-14 Thread eryksun
On Tue, Jan 14, 2014 at 3:22 AM, Krischu wrote: > When I started I had In [0]:, In[1] etc. > > Now the notebook starts with In [2]:, In [3]: then In [9]: > > Yesterday before storing and leaving the notebook I suddenly had all In[]'s > marked like In [*]: > > Is there a method behind this? Can one

Re: [Tutor] Interactive escape sequences

2014-01-14 Thread eryksun
On Tue, Jan 14, 2014 at 2:42 AM, Christian Alexander wrote: > > Why does the interactive prompt not recognize escape sequences in strings? > It only works correctly if I use the print function in python 3. > "Hello\nWorld" > "Hello\nWorld" Let's manually compile the following source string:

Re: [Tutor] another better way to do this ?

2014-01-13 Thread eryksun
On Mon, Jan 13, 2014 at 1:36 PM, Keith Winston wrote: > Yikes, Peter, that's scary. Wow. Yikes, watch the top posting. :) >> In the mean time here is my candidate: >> >> def test(a, b): >> a = iter(a) >> return all(c in a for c in b) Refer to the language reference discussion of compari

Re: [Tutor] another better way to do this ?

2014-01-12 Thread eryksun
On Sun, Jan 12, 2014 at 2:38 PM, Keith Winston wrote: > On Sun, Jan 12, 2014 at 2:22 PM, Keith Winston wrote: >> if test: > > Sigh and this line needs to read (if it's going to do what I said): > > if test != -1: Consider the case of `product == "letter"`. Do you want to doub

Re: [Tutor] another better way to do this ?

2014-01-12 Thread eryksun
On Sun, Jan 12, 2014 at 8:21 AM, Peter Otten <__pete...@web.de> wrote: > > OP: You'll get bonus points (from me, so they're pointless points, but > still) if you can solve this (including the fifth apocryphal test case) > using the collections.Counter class. Hint: >>> print(Counter.__sub__.__

Re: [Tutor] Windows Install Issue

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 10:24 AM, Matthew Ngaha wrote: > > """Unfortunately it is not possible to use both the PyQt4 and PyQt5 > installers at the same time. If you wish to have both PyQt4 and PyQt5 > installed at the same time you will need to build them yourself from > the source packages.""" >

Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Fri, Jan 10, 2014 at 11:48 PM, daedae11 wrote: > p = subprocess.Popen(['E:/EntTools/360EntSignHelper.exe', > 'E:/build/temp/RemoteAssistSetup.exe'], > stdout=subprocess.PIPE, shell=True).stdout Is 360EntSignHelper supposed to run RemoteAssistSetup as a child process? O

Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 12:51 AM, Steven D'Aprano wrote: > >> However, when I writed it into a .py file and execute the .py file, it >> blocked at "temp=p.readline()". > > Of course it does. You haven't actually called the .exe file, all you > have done is created a Popen instance and then grabbed

Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 12:46 AM, Danny Yoo wrote: > There is a warning in the documentation on subprocess that might be > relevant to your situation: > > Warning: > Use communicate() rather than .stdin.write, .stdout.read or > .stderr.read to avoid deadlocks due to any of the other OS pip

Re: [Tutor] garbage collecting

2014-01-08 Thread eryksun
On Wed, Jan 8, 2014 at 3:30 PM, Oscar Benjamin wrote: > The garbage collector has nothing to do with the memory usage of immutable > types like ints. There are deallocated instantly when the last reference you > hold is cleared (in CPython). So if you run out of memory because of them > then it is

Re: [Tutor] recursion depth

2014-01-08 Thread eryksun
On Wed, Jan 8, 2014 at 3:25 PM, Keith Winston wrote: > I've been playing with recursion, it's very satisfying. > > However, it appears that even if I sys.setrecursionlimit(10), it blows > up at about 24,000 (appears to reset IDLE). I guess there must be a lot of > overhead with recursion, if o

Re: [Tutor] OverflowError: cannot fit 'long' into an index-sized integer

2014-01-07 Thread eryksun
On Tue, Jan 7, 2014 at 4:49 AM, Jorge L. wrote: > > When i test that script against 600851475143 I get the following error You're trying to create a list with over 600 billion items. sys.maxsize is a bit over 2 billion for 32-bit CPython, but switching to 64-bit won't help unless you have a few t

  1   2   3   4   5   6   7   >