Re: [Tutor] reading an input stream

2015-12-24 Thread eryk sun
On Thu, Dec 24, 2015 at 9:13 PM, boB Stepp wrote: > AttributeError: 'generator' object has no attribute 'next' The iterator protocol was added in Python 2.2 (circa 2001) as a generalization for use in "for" loops, but the language didn't have built-in next() at the time. Instead the method to get

Re: [Tutor] Python 3.5.1 64 bit?

2016-01-05 Thread eryk sun
On Tue, Jan 5, 2016 at 5:50 PM, Alan Gauld wrote: > On 05/01/16 19:47, yehudak . wrote: >> I'm using version 3.5 of Python and want to upgrade. > > 3.5 is the latest stream. If you are already using it why > do you want to upgrade? Its easy to get caught up in a frenzy > of chasing the latest dot

Re: [Tutor] Python 3.5.1 64 bit?

2016-01-06 Thread eryk sun
On Wed, Jan 6, 2016 at 1:06 AM, yehudak . wrote: > What's wrong with upgrading to newer version? It depends on how many systems and virtual environments that you're upgrading. It shouldn't be an issue if it's just a new micro release for your own development machine. If you come across a regressi

Re: [Tutor] Question about the memory manager

2016-01-13 Thread eryk sun
On Wed, Jan 13, 2016 at 2:01 AM, Albert-Jan Roskam wrote: > I sometimes check the Task Manager to see how much RAM is in use. Is there a > Python way to do something similar? Use the psutil module to solve this problem across platforms. For Windows only, you can use ctypes to call GetProcessMemo

Re: [Tutor] Question about the memory manager

2016-01-14 Thread eryk sun
On Thu, Jan 14, 2016 at 3:03 AM, Albert-Jan Roskam wrote: > > These two pages are quite nice. The author says the memory used by small > objects is > never returned to the OS, which may be problematic for long running processes. The article by Evan Jones discusses a patch to enable releasing unu

Re: [Tutor] Simultaneous read and write on file

2016-01-18 Thread eryk sun
On Mon, Jan 18, 2016 at 10:01 AM, Anshu Kumar wrote: > I have read in documentation that wb+ mode is for writing and reading. Am i > using wrong mode, should i use rb+ ? Use w+ to create a new file, opened with read and write access. Use r+ to open an existing file with read and write access. Unl

Re: [Tutor] Simultaneous read and write on file

2016-01-18 Thread eryk sun
On Mon, Jan 18, 2016 at 10:04 PM, Martin A. Brown wrote: > The above is a very handy chart. Did you find this somewhere, eryk > sun, or is this from your own knowledge and experience? The mapping to POSIX open flags is from a table in the POSIX fopen spec [1] as well as the Windows CRT do

Re: [Tutor] lc_ctype and re.LOCALE

2016-01-29 Thread eryk sun
On Thu, Jan 28, 2016 at 2:23 PM, Albert-Jan Roskam wrote: > Out of curiosity, I wrote the throw-away script below to find a character > that is classified > (--> LC_CTYPE) as digit in one locale, but not in another. The re module is the wrong tool for this. The re.LOCALE flag is only for byte st

Re: [Tutor] Surprised that print("a" "b") gives "ab"

2016-03-06 Thread eryk sun
On Sun, Mar 6, 2016 at 9:52 AM, Steven D'Aprano wrote: > On Sun, Mar 06, 2016 at 01:03:01AM -0600, boB Stepp wrote: > >> get your semantics point, but are there two string objects created in >> both approaches or does the first in fact create only a single object? >> If the first truly only creat

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread eryk sun
On Sat, Mar 12, 2016 at 12:46 AM, boB Stepp wrote: > I did with the non-printing control character, but not with '\u25ba' ! > So I had to go through some contortions after some research to get my > Win7 cmd.exe and PowerShell to display the desired prompt using The console is hosted by another p

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-13 Thread eryk sun
On Sun, Mar 13, 2016 at 3:14 AM, Albert-Jan Roskam wrote: > I thought that utf-8 (cp65001) is by definition (or by design?) impossible > for console output in windows? Aren't there "w" (wide) versions of functions > that do accept utf-8? The wide-character API works with the native Windows charac

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-15 Thread eryk sun
On Tue, Mar 15, 2016 at 2:51 PM, Albert-Jan Roskam wrote: > > So windows uses the following (Western locales): > console: cp437 (OEM codepage) > "bytes": cp1252 (ANSI codepage) The console defaults to the OEM codepage, but you can separately switch the input and output to different codepages. Thi

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-15 Thread eryk sun
On Tue, Mar 15, 2016 at 4:40 PM, Alan Gauld wrote: > On 15/03/16 19:51, Albert-Jan Roskam wrote: > >> Sheesh, so much room for errors. Why not everything utf-8, like in linux? >> Is cmd.exe that impopular that Microsoft does not replace it with something >> better? > > It's replaced by Powershell

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-15 Thread eryk sun
On Tue, Mar 15, 2016 at 7:45 PM, boB Stepp wrote: > On Tue, Mar 15, 2016 at 7:35 PM, boB Stepp wrote: >> Is the following result in PowerShell related to what Eryk has been >> discussing? >> >> Windows PowerShell >> Copyright (C) 2009 Microsoft Corporation. All rights reserved. >> >> PS C:\Windo

Re: [Tutor] (SIP installation problem) Best way to install Python 3 onto Windows 10

2016-03-18 Thread eryk sun
On Thu, Mar 17, 2016 at 6:36 AM, CMG Thrissur wrote: > Thank you for the link but on that page i see mention of SIP requirement, is > that required for binary package also. The .exe and .whl packages for PyQt are self-contained. You don't need anything else, and you don't have to build anything f

Re: [Tutor] (SIP installation problem) Best way to install Python 3 onto Windows 10

2016-03-20 Thread eryk sun
On Wed, Mar 16, 2016 at 12:56 PM, Alan Gauld wrote: > On 16/03/16 12:46, CMG Thrissur wrote: > >> I tried to install activestate on win 10 but due to my ignorance or >> lack of knowlege i could n't get to install pyqt or sip. i tried it >> through pip. PyQt can't be easily installed from source

Re: [Tutor] Fwd: Newbie trying to get pip run on windows 7

2016-04-20 Thread eryk sun
On Tue, Apr 19, 2016 at 11:26 PM, Gustavo Davis via Tutor wrote: > But for some reason after I made the changes and saved them they wont > run. I mean once I go to the file and right click on them and click run > the cmd prompt pops up for a moment and then it just closes down and the > pip mo

Re: [Tutor] int(1.99...99) = 1 and can = 2

2016-05-01 Thread eryk sun
On Sun, May 1, 2016 at 1:02 AM, boB Stepp wrote: > > py3: 1. > 2.0 > py3: 1.999 > 1.999 ... > It has been many years since I did problems in converting decimal to > binary representation (Shades of two's-complement!), but I am under > the (apparently mistake

Re: [Tutor] Howto display progress as cmd is being executed via subprocess ?

2016-06-14 Thread eryk sun
On Mon, Jun 13, 2016 at 4:50 PM, Ramanathan Muthaiah wrote: > > subprocess.check_output([cmd], stderr=subprocess.STDOUT, shell=True) > ... > how to combine the progressbar and subprocess code snippets to show the > progress as the cmd is being executed. check_output waits for the process to exit,

Re: [Tutor] capture output from a subprocess while it is being produced

2016-06-14 Thread eryk sun
On Tue, Jun 14, 2016 at 8:03 PM, Albert-Jan Roskam wrote: > > proc = Popen("ls -lF", cwd=cwd, shell=True, stdout=PIPE, stderr=PIPE) Don't use shell=True if you can avoid it. "ls" isn't a shell command. Use ['ls', '-lF']. The child process probably buffers its output when stdout isn't a termi

Re: [Tutor] Why are expressions not allowed as parameters in function definition statements?

2016-06-18 Thread eryk sun
On Sun, Jun 19, 2016 at 4:04 AM, Danny Yoo wrote: > >> def f((x,y), z): > ... print x, y, z > ... >> f([1, 2], 3) > 1 2 3 Note that Python 3 doesn't support tuple parameter unpacking. See PEP 3113: https://www.python.org/dev/peps/pep-3113 ___ Tu

Re: [Tutor] iterators

2016-07-04 Thread eryk sun
On Mon, Jul 4, 2016 at 9:56 PM, Danny Yoo wrote: > So the extra trailing comma in a 1-tuple parenthesized expression is > just there to make it different looking, to disambiguate it from the > use of parentheses for expression grouping. The comma is the distinguishing element of non-empty tuple l

Re: [Tutor] Quote and double quotes opens up File Explorer in Windows 10

2016-07-09 Thread eryk sun
On Sat, Jul 9, 2016 at 2:22 PM, Ken G. wrote: > Hi: In gradually moving over my Python programs (2.7.6) to Windows 10 and > using Geany 1.27 to modify or write up a program there, it is noted that > whenever I typed in a quote (') or double quote ("), Windows 10 File > Explorer opens up. I end up

Re: [Tutor] (no subject)

2016-07-25 Thread eryk sun
On Fri, Jul 22, 2016 at 7:38 AM, DiliupG wrote: > I am using Python 2.7.12 on Windows 10 > > filename = u"මේක තියෙන්නේ සිංහලෙන්.txt" > Unsupported characters in input That error message is from IDLE. I'm not an expert with IDLE, so I don't know what the following hack potentially breaks, but it d

Re: [Tutor] (no subject)

2016-07-25 Thread eryk sun
On Mon, Jul 25, 2016 at 10:28 AM, Steven D'Aprano wrote: > I know that Linux and Mac OS X both use UTF-8 for filenames, and so support > all > of Unicode. But Windows, I'm not sure. It might be localised to only use > Latin-1 > (Western European) or similar. Windows filesystems (e.g. NTFS, ReFS

Re: [Tutor] (no subject)

2016-07-25 Thread eryk sun
On Tue, Jul 26, 2016 at 4:39 AM, DiliupG wrote: > I am reading in a list of file names with the following code. > > def get_filelist(self): > "" > app = QtGui.QApplication(sys.argv) > a = QtGui.QFileDialog.getOpenFileNames() > > filelist = [] > if a:

Re: [Tutor] command to determine of python 32 or 64 bit?

2016-08-10 Thread eryk sun
On Wed, Aug 10, 2016 at 4:27 AM, Garry Willgoose wrote: > I have a number of binary libraries that are dependent on whether the > precompiled python > distribution (eg. Enthought, ActiveState, etc) in which they are installed > are compiled with > 32 or 64 bit. Is there any reliable way to dete

Re: [Tutor] Where is win32print in Windows 10 Pro

2016-08-12 Thread eryk sun
On Thu, Aug 11, 2016 at 2:44 PM, Joaquin Alzola wrote: > >>import win32print >>ImportError: No module named win32print > > That module doesn't exist on your python path > > 'pywin32' is its canonical name. > > http://sourceforge.net/projects/pywin32/ I'm not certain what's meant in the above, but

Re: [Tutor] __init__

2016-08-30 Thread eryk sun
On Tue, Aug 30, 2016 at 9:09 AM, Alan Gauld via Tutor wrote: > new() that sets up the memory then calls init(). So init is > only used to initialise the object after it has been > constructed. __new__ and __init__ are called by the metaclass __call__ method. __init_ is called if __new__ returns a

Re: [Tutor] @property for old style classes vs new style classes

2016-09-15 Thread eryk sun
On Thu, Sep 15, 2016 at 4:40 AM, monik...@netzero.net wrote: > class GetSet(): > > def __init__(self, value): > self.attrval = value > > @property > def var(self): > print "getting the var attribute" > return self.attrval > @var.setter > def var(self,val

Re: [Tutor] @property for old style classes vs new style classes

2016-09-15 Thread eryk sun
On Thu, Sep 15, 2016 at 9:48 PM, monik...@netzero.net wrote: > But why var is in class __dict__? > Does @property make it a class attribute? An instance of `property` is a data descriptor, i.e. it implements the __get__, __set__, and __delete__ methods of the descriptor protocol. A non-data descr

Re: [Tutor] Python IDLE for Windows 10, 64-bit

2016-09-21 Thread eryk sun
On Wed, Sep 21, 2016 at 3:14 PM, Aaron Rose wrote: > I'm looking for a link for Python IDLE for Windows 10, 64-bit. Can't seem to > find > the right link on python.org. Could someone kindly point me in the right > direction? Python's installer has an option to install IDLE. Here's the link fo

Re: [Tutor] help with Numpy

2016-09-21 Thread eryk sun
On Wed, Sep 21, 2016 at 2:53 PM, Paul Dentinger wrote: > > I need Numpy and Scipy and may need matplotlib. So I tried to call Numpy and > it > can't be found. So I go online and find Numpy and download it. Read the following docs on Python packaging and pip: https://pip.pypa.io https://packag

Re: [Tutor] Python IDLE for Windows 10, 64-bit

2016-09-21 Thread eryk sun
On Wed, Sep 21, 2016 at 9:21 PM, Alan Gauld via Tutor wrote: > On Windows it is usually installed by default at: > > %PYTHONDIR%/Lib/idelib/idle.bat With Python 3, you can run the package as a script: pythonw -m idlelib Python 2: pythonw -m idlelib.idle

Re: [Tutor] help with Numpy

2016-09-21 Thread eryk sun
On Wed, Sep 21, 2016 at 10:35 PM, Oscar Benjamin wrote: > I would have given the same advice a year or so ago. It's worth noting > though that the situation with pip, wheel etc has improved significantly > recently. It's now straightforward to pip install Numpy, scipy, matplotlib > and many others

Re: [Tutor] using python shell program on windows

2016-10-14 Thread eryk sun
On Fri, Oct 14, 2016 at 4:52 PM, Peter Otten <__pete...@web.de> wrote: > > python -m pip install timesheet > > on the commandline should take care of the details. On my (Linux) machine > this also installed a script that I can invoke on the command line with > > $ timesheet start foo bar > Started

Re: [Tutor] Python 3.5 installation beside Python 2.3 on Windows 7

2016-10-22 Thread eryk sun
On Sun, Oct 23, 2016 at 1:39 AM, Pierre-Michel Averseng wrote: > Le 22/10/2016 à 20:00, tutor-requ...@python.org a écrit : > >> Do I have to completely uninstall Python 2.7.1 and then install Python >> 3.5.2? Or can I still install Python 3.5.2 keeping Python 2.7.1 untouched >> on my laptop? > > F

Re: [Tutor] Q regarding external program calling

2016-11-07 Thread eryk sun
On Sun, Nov 6, 2016 at 9:09 AM, Alan Gauld via Tutor wrote: > On 06/11/16 01:44, Clayton Kirkwood wrote: >> Looked all over, but haven't found the answer. If I have a (windows) program >> which I wish to start, even shell scripts, and possibly capture the output >> from, how do I do that? > > Othe

Re: [Tutor] Trouble Launching Python

2016-12-20 Thread eryk sun
On Mon, Dec 19, 2016 at 10:38 PM, Joseph Olugbohunmi via Tutor wrote: > Hello,Good day, I installed Python 3.5.2 on my Windows 8.1 PC and then I > tried launching > IDLE as well as the Interpreter but I got a message that > api-ms-win-crt-runtime-l1-1-0.dll was > missing. I downloaded and instal

Re: [Tutor] Trouble Launching Python

2016-12-21 Thread eryk sun
On Tue, Dec 20, 2016 at 7:12 PM, George Fischhof wrote: > 2016-12-19 23:38 GMT+01:00 Joseph Olugbohunmi via Tutor : > > this is a Microsoft visual c++ redistributable is missing from system. > I found this stackoverflow link which seems to describing a solution > > http://stackoverflow.com/questio

Re: [Tutor] Open a libreoffice calc file in Python

2016-12-21 Thread eryk sun
On Thu, Dec 22, 2016 at 4:50 AM, wrote: > BTW, the array form is Popen's default mode; sensibly you need to _ask_ to > use a shell string with shell=True, because that is harder and more fragile. Without shell=True, args as a string on POSIX is generally an error because it will look for the ent

Re: [Tutor] Open a libreoffice calc file in Python

2016-12-22 Thread eryk sun
On Thu, Dec 22, 2016 at 4:20 PM, boB Stepp wrote: > > Both you and Eryk seem to be speaking in terms of using > subprocess.Popen() directly. So I think I need some clarification. > At > https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module > it says: > > "The recommended

Re: [Tutor] ReadableInt

2016-12-30 Thread eryk sun
On Fri, Dec 30, 2016 at 4:46 PM, Albert-Jan Roskam wrote: > > Remember I only intend to use it while debugging the given script. Have you tried hooking sys.displayhook? > Why does the call to str() below return '1' and not 'one'? Should I implement > __new__ > because int is immutable? You can

Re: [Tutor] Best Python 3 module to create simple text editor in Windows command prompt?

2017-02-02 Thread eryk sun
On Fri, Feb 3, 2017 at 2:22 AM, boB Stepp wrote: > What would be the best Python 3 module to best assist me in controlling > the command prompt window display, font colors, positioning the cursor > dynamically, etc.? Try using curses [1]. Christoph Gohlke has a port for Windows Python based on th

Re: [Tutor] sort() method and non-ASCII

2017-02-04 Thread eryk sun
On Sun, Feb 5, 2017 at 3:52 AM, boB Stepp wrote: > Does the list sort() method (and other sort methods in Python) just go > by the hex value assigned to each symbol to determine sort order in > whichever Unicode encoding chart is being implemented? list.sort uses a less-than comparison. What you

Re: [Tutor] sort() method and non-ASCII

2017-02-05 Thread eryk sun
On Sun, Feb 5, 2017 at 10:30 PM, boB Stepp wrote: > I was looking at http://unicode.org/charts/ Because they called them > charts, so did I. I'm assuming that despite this organization into > charts, each and every character in each chart has its own unique > hexadecimal code to designate each c

Re: [Tutor] Test for type(object) == ???

2017-02-10 Thread eryk sun
On Sat, Feb 11, 2017 at 1:34 AM, boB Stepp wrote: > I was playing around with type() tonight. If I type (pun intended), I get: > > py3: type(5) > `type` is a metaclass that either creates a new class (given 3 arguments: name, bases, and dict) or returns a reference to the class of an existing o

Re: [Tutor] Test for type(object) == ???

2017-02-10 Thread eryk sun
On Sat, Feb 11, 2017 at 4:32 AM, boB Stepp wrote: > > This bit got me experimenting. Since the integer "5" is an integer > object instance, I am wondering why I can't do: > > py3: 5.__repr__() > File "", line 1 > 5.__repr__() > ^ > SyntaxError: invalid syntax > > , but I can do

Re: [Tutor] Test for type(object) == ???

2017-02-10 Thread eryk sun
On Sat, Feb 11, 2017 at 3:22 AM, boB Stepp wrote: > > py3: help(repr) > Help on built-in function repr in module builtins: > > repr(obj, /) > Return the canonical string representation of the object. > > For many object types, including most builtins, eval(repr(obj)) == obj. > > Question:

Re: [Tutor] Test for type(object) == ???

2017-02-10 Thread eryk sun
On Sat, Feb 11, 2017 at 6:22 AM, boB Stepp wrote: > On Fri, Feb 10, 2017 at 11:49 PM, eryk sun wrote: > >> It's from the function's __text_signature__. >> >> >>> repr.__text_signature__ >> '($module, obj, /)' >> >>

Re: [Tutor] Test for type(object) == ???

2017-02-11 Thread eryk sun
On Sat, Feb 11, 2017 at 7:35 AM, boB Stepp wrote: > Has this PEP been implemented yet? I am running Python 3.5.2 and it > appears not to work. Also, in "What's New In Python 3.6" > (https://docs.python.org/3/whatsnew/3.6.html) I did not see a mention > of it. You can see in the document header

Re: [Tutor] Python-list thread: int vs. float

2017-02-11 Thread eryk sun
On Sat, Feb 11, 2017 at 8:06 AM, Steven D'Aprano wrote: > Valid digits for integers include 0 through 9 in decimal Note that Python 3 uses the Unicode database to determine the decimal value of characters, if any. It's not limited to the ASCII decimal digits 0-9. For example: >>> s '௧꘢୩'

Re: [Tutor] Python-list thread: int vs. float

2017-02-12 Thread eryk sun
On Sat, Feb 11, 2017 at 8:53 PM, boB Stepp wrote: > > I suspect Eryk had set a normal 's' as an identifier for the character > code sequence that produces the non-ASCII output, but forgot to show > us that step. But I could be mistaken. Sorry, I forgot to show the assignment of the string "௧꘢୩"

Re: [Tutor] Exponential function

2017-02-14 Thread eryk sun
On Tue, Feb 14, 2017 at 11:01 PM, Alan Gauld via Tutor wrote: > To compute it if you don't know x in advance then yes, > use something like > > value = 10**x > > But if you know the value in advance you can write it in > a more compact form as: > > value = 1e5 # or 3e7 or whatever... 10**5 is an

Re: [Tutor] subprocess.Popen / proc.communicate issue

2017-03-30 Thread eryk sun
On Thu, Mar 30, 2017 at 10:51 PM, Cameron Simpson wrote: > This suggests that .communicate uses Threads to send and to gather data > independently, and that therefore the deadlock situation may not arise. For Unix, communicate() uses select or poll. It uses threads on Windows. Either way it avoid

Re: [Tutor] reading files in Python 3

2017-03-30 Thread eryk sun
On Thu, Mar 30, 2017 at 8:47 PM, Zachary Ware wrote: > In this case, the problem is the bogus Unicode escape that you > inadvertently included in your path: `\Us...`. To fix it, either use a > 'raw' string (`r"C:\Users\..."`) or use forward slashes rather than > backslashes, which Windows is happ

Re: [Tutor] reading files in Python 3

2017-03-31 Thread eryk sun
On Thu, Mar 30, 2017 at 8:45 PM, Mats Wichmann wrote: > Yeah, fun. You need to escape the \ that the idiot MS-DOS people chose > for the file path separator. Because \ is treated as an escape character. The COMMAND.COM shell inherited command-line switches (options) that use slash from TOPS-10 b

Re: [Tutor] Count for loops

2017-04-11 Thread eryk sun
On Wed, Apr 12, 2017 at 3:40 AM, boB Stepp wrote: > > I have to say I am surprised by this as well as the OP. I knew that > str() in general makes a nice printable representation The single-argument str() constructor calls the object's __str__ method (or __repr__ if __str__ isn't defined). In Py

Re: [Tutor] Count for loops

2017-04-11 Thread eryk sun
On Wed, Apr 12, 2017 at 4:03 AM, boB Stepp wrote: > > I have not used the decimal module (until tonight). I just now played > around with it some, but cannot get it to do an exact conversion of > the number under discussion to a string using str(). Pass a string to the constructor: >>> d =

Re: [Tutor] classproperty for Python 2.7 (read-only enough)

2017-04-19 Thread eryk sun
On Wed, Apr 19, 2017 at 10:19 AM, Peter Otten <__pete...@web.de> wrote: > Steven D'Aprano wrote: > >> As I said, I haven't had a chance to try Peter's code, so it's possible >> that he's solved all these problems. I'm judging by previous > > No, my simple code only "works" for read-only properties

Re: [Tutor] Sets question

2017-04-26 Thread eryk sun
On Thu, Apr 27, 2017 at 12:33 AM, Phil wrote: > Another question I'm afraid. > > If I want to remove 1 from a set then this is the answer: > > set([1,2,3]) - set([1]) You can also use set literals here, with the caveat that {} is ambiguous, and Python chooses to make it an empty dict instead of a

Re: [Tutor] Sets question

2017-04-26 Thread eryk sun
On Thu, Apr 27, 2017 at 1:34 AM, Phil wrote: > I did try {int(num)} but that resulted in an error that said something along > the lines of int not being iterable. I'll have another look at that idea. That exception indicates you probably used set(int(num)) instead of either {int(num)} or set([int

Re: [Tutor] Difference between %f and %F string formatting?

2017-04-26 Thread eryk sun
On Thu, Apr 27, 2017 at 2:19 AM, Tim Peters wrote: > [boB Stepp ] > >> I cannot find any discernible >> difference between '%f' % and '%F' % >> . Is there any or do they duplicate >> functionality? If the latter, why are there two ways of doing the >> same thing? > > They differ only in the ca

Re: [Tutor] [ctypes-users] Press ESC to exit()

2017-05-01 Thread eryk sun
On Mon, May 1, 2017 at 6:28 PM, Michael C wrote: > Hi all, I found out that one way to press ESC to kill the script was to use > my previous > script language, AutoHotKey and this is how it works: > > AutoHotKey code > ## function that kills the window with title '*Python 3.6.1 Shell*' > > kill()

Re: [Tutor] [ctypes-users] Press ESC to exit()

2017-05-01 Thread eryk sun
On Tue, May 2, 2017 at 3:03 AM, Michael C wrote: > holy cow The code for a global keyboard hook is a bit complex - mostly because I had to use ctypes (properly instead of an unreliable hack). Normally an application has one or more windows and a message loop, in which case there's no need for suc

Re: [Tutor] Hi all: How do I save a file in a designated folder?

2017-05-02 Thread eryk sun
On Tue, May 2, 2017 at 6:09 PM, Michael C wrote: > screenshot.save("\test\missed.png") You probably know that "\t" represents a tab in a string literal, but there's something about working with a path that causes people to overlook this. Windows won't overlook it. Control characters, i.e. charact

Re: [Tutor] Subtract a 1D Array from a 2D Array

2017-05-13 Thread eryk sun
On Sat, May 13, 2017 at 1:33 PM, Stephen P. Molnar wrote: > I am using Python 3.6 in Anaconda3 Spyder IDE. > > I have two arrays: > > X Y Z > a > 0 0 0 > 2.059801 0 0 > -1.2031263.402953

Re: [Tutor] Python Image Library

2017-05-17 Thread eryk sun
On Wed, May 17, 2017 at 8:24 PM, Michael C wrote: > from PIL import Image > > im = Image.open('pic.bmp') > im.show() > > I ran this code and it not only opened the picture in paint, which is what > I want, but it also opens a CMD.exe console window! how do I prevent that from > happening? You're

Re: [Tutor] Python Image Library

2017-05-17 Thread eryk sun
On Wed, May 17, 2017 at 10:33 PM, Michael C wrote: > On Wed, May 17, 2017 at 3:30 PM, eryk sun wrote: > >> You're probably running a .py script that's associated with py.exe or >> python.exe. These executables create a new console (i.e. an instance >> of the

Re: [Tutor] Python Image Library

2017-05-17 Thread eryk sun
On Thu, May 18, 2017 at 1:58 AM, Michael C wrote: > when I run this, while it's called test.pyw, this pops up > > from PIL import Image > > im = Image.open('1.bmp') > im.show() Ok, I stand corrected. It's something weird, and most likely due to Windows support here being an afterthought throw in

Re: [Tutor] call key on_press event multiple times when key is held down

2017-07-04 Thread eryk sun
On Tue, Jul 4, 2017 at 8:50 AM, Carlton Banks wrote: > I am using pynput for keyboard events You could use an event that enables a recording loop. The on_press and on_release callbacks of the Listener [1] would set() and clear() this event, respectively. For

Re: [Tutor] Probably a silly question: how to install lxml?

2017-07-05 Thread eryk sun
On Thu, Jul 6, 2017 at 1:51 AM, Steven D'Aprano wrote: > > I dunno, to me it sounds like it *didn't* work, not if it is printing > red error messages at the end. What do they say? lxml should install from a wheel (e.g. lxml-3.8.0-cp36-cp36m-win_amd64.whl). There's nothing to build, so the most li

Re: [Tutor] Python __del__ method

2017-07-11 Thread eryk sun
On Tue, Jul 11, 2017 at 2:47 PM, Jia Yue Kee wrote: > > Case 2: If I were to run the code in "Interactive Mode", the following output > will be obtained: > x = Robot("Tik-Tok") > Tik-Tok has been created! y = Robot("Jenkins") > Jenkins has been created! z = x z > <__main__.Rob

Re: [Tutor] Python __del__ method

2017-07-11 Thread eryk sun
On Wed, Jul 12, 2017 at 12:07 AM, eryk sun wrote: > On Tue, Jul 11, 2017 at 2:47 PM, Jia Yue Kee > wrote: >> >> Case 2: If I were to run the code in "Interactive Mode", the following >> output will be obtained: >> >>>>> x = Robot("Tik

Re: [Tutor] pythonic ascii decoding!

2017-07-31 Thread eryk sun
On Mon, Jul 31, 2017 at 3:39 PM, bruce wrote: > > So, is there a quick/dirty approach I can use to simply strip out the > "non-ascii" chars. I know, this might not be the "best/pythonic" way, > and that it might result in loss of some data/chars, but I can live > with it for now. Ignore or replac

Re: [Tutor] What is meaning of "/" in "pow(x, y, z=None, /)"?

2017-08-02 Thread eryk sun
On Wed, Aug 2, 2017 at 1:06 AM, boB Stepp wrote: > I had typed help(pow) in the interpreter and got: > > > py3: help(pow) > Help on built-in function pow in module builtins: > > pow(x, y, z=None, /) > Equivalent to x**y (with two arguments) or x**y % z (with three arguments) > > Some type

Re: [Tutor] if __name__=='main' vs entry points: What to teach new comers?

2017-08-02 Thread eryk sun
On Wed, Aug 2, 2017 at 4:06 PM, Wolfgang Maier wrote: > On 08/02/2017 04:57 PM, Steven D'Aprano wrote: > >> I have a module with a main() function and an "if __name__ == ..." >> guard. Under what circumstances is that not sufficient, and I would want >> console_scripts? > > If you install things u

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-03 Thread eryk sun
On Thu, Aug 3, 2017 at 4:22 PM, Chris Warrick wrote: > > Simple: `scripts` are legacy. `entry_points` are the new thing. > There’s also a third approach: gui_scripts entry_points, which work > the same way on Linux/*nix, but on Windows, it means that running your > script by opening the created .e

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-04 Thread eryk sun
On Fri, Aug 4, 2017 at 10:15 AM, Thomas Güttler wrote: > Am 04.08.2017 um 02:50 schrieb Ben Finney: > >> Because Distutils implements only ‘scripts’, and that's not capable >> enough for what people need so Setuptools implements entry points. >> >> In other words: One of them is in the standard li

Re: [Tutor] Difference(s) betweenPython 3 static methods with and without @staticmethod?

2017-08-06 Thread eryk sun
On Sun, Aug 6, 2017 at 11:35 PM, boB Stepp wrote: > > I see no difference in result, whether I use the @staticmethod decorator or > not. While a staticmethod and a function are both descriptors [1], a staticmethod is basically a no-op descriptor. Its __get__ method always returns its unbound cal

Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-07 Thread eryk sun
On Tue, Aug 8, 2017 at 3:20 AM, Cameron Simpson wrote: > > As you note, the 16 and 32 forms are (6 + 1) times 2 or 4 respectively. This > is because each encoding has a leading byte order marker to indicate the big > endianness or little endianness. For big endian data that is \xff\xfe; for > litt

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-09 Thread eryk sun
On Wed, Aug 9, 2017 at 11:32 PM, Alan Gauld via Tutor wrote: > On 09/08/17 22:15, Steven D'Aprano wrote: >> >> This is the critical factor. How can you use *by default* something that >> is *NOT* supplied by default? > > I have to agree with Steven here. Any mature language should > ship with all

Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-10 Thread eryk sun
On Fri, Aug 11, 2017 at 2:34 AM, Cameron Simpson wrote: > > In files however, the default encoding for text files is 'utf-8': Python > will read the file's bytes as UTF-8 data and will write Python string > characters in UTF-8 encoding when writing. The default encoding for source files is UTF-8.

Re: [Tutor] Percentage of installations without setuptools (Was if __name__=='__main__' ...)

2017-08-11 Thread eryk sun
On Fri, Aug 11, 2017 at 6:27 PM, Alan Gauld via Tutor wrote: > On 11/08/17 19:13, Chris Warrick wrote: > >> False since Python 3.4/2.7.9. ensurepip installs Python on every new >> Python install. > > Sorry Chris, that's not making sense? Do you mean ensurepip > installs setuptools on every install

Re: [Tutor] logging to cmd.exe

2017-09-26 Thread eryk sun
> cmd.exe can use cp65001 aka utf8??? CMD is a Unicode application that for the most part uses WinAPI wide-character functions, including the console API functions (as does Python 3.6+). There are a few exceptions. CMD uses the console codepage when decoding batch files (line by line, so you can c

Re: [Tutor] logging to cmd.exe

2017-09-26 Thread eryk sun
On Tue, Sep 26, 2017 at 7:35 AM, Mats Wichmann wrote: > On 09/26/2017 05:22 AM, Albert-Jan Roskam wrote: > >> Rather than change your code can you change the codepage with the chcp >> command? > > the way chcp takes effect is problematic for this: > > "Programs that you start after you assign a ne

Re: [Tutor] ctypes wintypes

2017-10-05 Thread eryk sun
On Tue, Oct 3, 2017 at 10:30 PM, Michael C wrote: > > I am trying to create SYSTEM_INFO structure and MEMORY_BASIC_INFORMATION > structure First, avoid relying on constants, enumerations, and structures published on MSDN. It's not always right. Get the SDK and use the header files instead. MEMOR

Re: [Tutor] ctypes wintypes

2017-10-05 Thread eryk sun
On Thu, Oct 5, 2017 at 8:27 PM, Michael C wrote: > > How do I see the values of each field? This doesn't work. > > print(PMEMORY_BASIC_INFORMATION.Protect) Create an instance of MEMORY_BASIC_INFORMATION and pass a pointer to it via byref(). For example, the following queries the region of memory

Re: [Tutor] ctypes wintypes

2017-10-06 Thread eryk sun
On Fri, Oct 6, 2017 at 7:26 PM, Michael C wrote: > > I started out with what you gave me: > [...] > > I am trying to acquire "lpMinimumApplicationAddress" and > "lpMaximumApplicationAddress" from system_info, so I did this, > >>code > Kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) > Ker

Re: [Tutor] ctypes wintypes

2017-10-06 Thread eryk sun
On Fri, Oct 6, 2017 at 7:43 PM, Michael C wrote: > Sorry but I dont understand this line: > > mbi = MEMORY_BASIC_INFORMATION() > > This creates a instance of the class? Yes, and this allocates sizeof(MEMORY_BASIC_INFORMATION) bytes at addressof(mbi), which you pass to a function by reference via

Re: [Tutor] ctypes wintypes

2017-10-06 Thread eryk sun
On Fri, Oct 6, 2017 at 9:12 PM, Michael C wrote: > > How do I create a buffer, or rather, is a buffer just a variable? A buffer is a block of memory for an I/O operation. For example, if you need to read a 4-byte (32-bit) integer at an address in another process, the 'buffer' could be ctypes.c_in

Re: [Tutor] ctypes wintypes

2017-10-06 Thread eryk sun
On Fri, Oct 6, 2017 at 10:06 PM, Michael C wrote: > like this? > > buffer = ctypes.byref(ctypes.create_string_buffer(4)) No, the buffer is the array created by create_string_buffer, which you pass byref(). In the following example I create a `test` buffer that contains "spam", and I use the pseud

Re: [Tutor] ctypes wintypes

2017-10-06 Thread eryk sun
On Fri, Oct 6, 2017 at 10:26 PM, Michael C wrote: > > base = mbi.BaseAddress > buffer = ctypes.c_int32() > buffer_pointer = ctypes.byref(buffer) > ReadProcessMemory = Kernel32.ReadProcessMemory > > if ReadProcessMemory(Process, base, buffer_pointer, mbi.RegionSize, None): > print('buffer i

Re: [Tutor] ctypes wintypes

2017-10-06 Thread eryk sun
On Fri, Oct 6, 2017 at 11:05 PM, Michael C wrote: > For this read process memory, if I am trying compose a LPCVOID > lpBaseAddress, am I not making a variable that equals to mbi.BaseAddress, > and then making a pointer pointing to it? > > start_address = mbi.BaseAddress > LPCVOID = ctypes.byref(

Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

2018-01-08 Thread eryk sun
On Sun, Jan 7, 2018 at 10:51 AM, Albert-Jan Roskam wrote: > > On Jan 7, 2018 09:08, Steven D'Aprano wrote: >> >> realpath() returns the canonical path of the given filename. It doesn't >> try to locate some actual existing file. > > I always thought that os.path.realpath is the Python equivalent

Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

2018-01-09 Thread eryk sun
On Tue, Jan 9, 2018 at 2:48 PM, Albert-Jan Roskam wrote: > > I think that it would be a great enhancement if os.realpath would return the > UNC path if > given a mapped drive in Windows, if needed as extended path (prefixed with > "\\?\UNC\"). > That's something I use all the time, unlike symlin

Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

2018-01-10 Thread eryk sun
On Wed, Jan 10, 2018 at 12:59 PM, Albert-Jan Roskam wrote: > > I tried: from os.path import _getfullpathname _getfullpathname(r"H:") > 'h:\\path\\to\\folder' import os os.getcwd() > 'h:\\path\\to\\folder' > > I expected h:\ to be \\server\share\foo. You called _getfullpathname

Re: [Tutor] When is and isn't "__file__" set?

2018-01-12 Thread eryk sun
On Fri, Jan 12, 2018 at 5:22 PM, Albert-Jan Roskam wrote: > On Jan 11, 2018 03:47, Steven D'Aprano wrote: >> >> Modules which are loaded from a .dll or .so binary file also should have >> __file__ set. > > And .pyd? I would hope so A .pyd is a Windows DLL (i.e. PE/COFF shared library). The .pyd

Re: [Tutor] Virtual environment question

2018-03-12 Thread eryk sun
On Mon, Mar 12, 2018 at 12:44 AM, Jim wrote: > > home = /usr/bin > include-system-site-packages = false [...] > resp = opener.open(request, timeout=self._timeout) > File "/usr/lib/python3.5/urllib/request.py", line 466, in open This is normal. Virtual environments are not isolated from the

Re: [Tutor] Virtual environment question

2018-03-12 Thread eryk sun
On Tue, Mar 13, 2018 at 1:31 AM, Jim wrote: > On 03/12/2018 04:04 AM, eryk sun wrote: >> >> On Mon, Mar 12, 2018 at 12:44 AM, Jim wrote: >>> >>> home = /usr/bin >>> include-system-site-packages = false >> >> [...] >>> >>>

  1   2   >