Re: [Python-Dev] [RELEASED] Python 3.3.0
On 29 September 2012 14:24, Eli Bendersky wrote: > On Sat, Sep 29, 2012 at 5:18 AM, Georg Brandl wrote: >> On behalf of the Python development team, I'm delighted to announce the >> Python 3.3.0 final release. >> > > Yay :) Agreed - this is a really nice release, thanks to all who put it together. Paul -- http://mail.python.org/mailman/listinfo/python-list
Registry entries set up by the Windows installer
I'm trying to get information on what registry entries are set up by the Python Windows installer, and what variations exist. I don't know enough about MSI to easily read the source, so I'm hoping someone who knows can help :-) As far as I can see on my PC, the installer puts entries HKLM\Software\Python\PythonCore\x.y with various bits underneath. I think I've seen indications that sometimes these are in HKCU, presumably for a "per user" install? If I manually hack around in the registry, and have both HKLM and HKCU, which one will Python use? Furthermore, more of a Windows question than Python, but there's a similar question with regard to the .py and .pyw file associations - they can be in HKLM\Software\Classes or HKCU\Software\Classes. Which takes precedence? I assume that the installer writes to HKLM for all users and HKCU for per-user installs. Is there anything else I've missed? The reason I ask, is that I'm starting to work with virtualenv, and I want to see what would be involved in (re-)setting the registry entries to match the currently active virtualenv. virtualenvwrapper- powershell seems to only deal with HKCU (which is a big plus on Windows 7, as it avoids endless elevation requests :-)) but that doesn't work completely cleanly with my all-users install. (Note: I'm not entirely sure that changing global settings like this to patch a per-console virtualenv is a good idea, but I'd like to know how hard it is before dismissing it...) Thanks, Paul. -- http://mail.python.org/mailman/listinfo/python-list
Re: Registry entries set up by the Windows installer
On 2 February 2012 00:28, Mark Hammond wrote: > For setting PYTHONPATH it uses both - HKEY_CURRENT_USER is added before > HKEY_LOCAL_MACHINE. I can't recall which one distutils generated > (bdist_wininst) installers will use - it may even offer the choice. [...] > Yep, I think that is correct. Thanks for the information. >> Is there anything else I've missed? > > I'm also not sure which one the pylauncher project will prefer, which may > become relevant should that get rolled into Python itself. Good point - I can look in the source for that, if I need to. >> The reason I ask, is that I'm starting to work with virtualenv, and I >> want to see what would be involved in (re-)setting the registry >> entries to match the currently active virtualenv. virtualenvwrapper- >> powershell seems to only deal with HKCU (which is a big plus on >> Windows 7, as it avoids endless elevation requests :-)) but that >> doesn't work completely cleanly with my all-users install. (Note: I'm >> not entirely sure that changing global settings like this to patch a >> per-console virtualenv is a good idea, but I'd like to know how hard >> it is before dismissing it...) > > > Out of interest, what is the reason forcing you to look at that - > bdist_wininst installers? FWIW, my encounters with virtualenv haven't > forced me to hack the registry - I just install bdist_wininst packages into > the "parent" Python which isn't ideal but works fine for me. This was a > year or so ago, so the world might have changed since then. It's bdist_msi.rather than bdist_wininst. I want to avoid putting packages into the "main" Python - at least, from my limited experiments the virtual environment doesn't see them (I may be wrong about this, I only did a very limited test and I want to do some more detailed testing before I decide). For bdist_wininst packages, I can install using easy_install - this will unpack and install bdist_wininst installers. (I don't actually like easy_install that much, but if it works...). But easy_install won't deal with MSI installers, and you can't force them to install in an unregistered Python. The only way I can think of is to do an "admin install" to unpack them, and put the various bits in place manually... The other reason for changing the registry is the .py file associations. But as I said, I'm not yet convinced that this is a good idea in any case... Thanks for the help, Paul. -- http://mail.python.org/mailman/listinfo/python-list
Windows: How do I copy a custom build of Python into a directory structure matching an MSI install?
I've got a build of Python (3.3) on my Windows PC. Everything is built, I believe (core, all modules, HTML help, etc). I want to "install" it on my PC (because tools like virtualenv expect a standard install layout, and the checkout basically isn't). I tried using Tools/msi/msi.py to build an installer, but it's making lots of assumptions and it's just becoming a pain (it's started asking me for certificates, and I need cabarc.exe). So I'm giving up on that approach, and just want to move the files into the right places. I can probably just copy stuff around till it works. I might even be able to decipher msi.py and work out how the installer lays things out. But I'm lazy, and I'm hoping that someone already knows and can tell me, or point me to some documentation that I've missed. In return, I'm willing to share the script I write to do the copying :-) Can anyone help? Thanks, Paul. -- http://mail.python.org/mailman/listinfo/python-list
Re: SnakeScript? (CoffeeScript for Python)
On Feb 2, 2:09 pm, Michal Hantl wrote: > I've been looking for something similar to CoffeeScript, but for python. > > Does anyone know of such project? Isn't CoffeeScript just a compiler to convert a cleaner syntax into Javascript? If so, why would you need such a thing for Python, where the syntax is already clean and simple? :-) Paul. -- http://mail.python.org/mailman/listinfo/python-list
What is the best way to freeze a Python 3 app (Windows)?
I want to package up some of my Python 3 scripts to run standalone, without depending on a system-installed Python. For my development, I use virtualenv and install all my dependencies in the virtualenv, develop the script and test it. When I'm done, I want to build an executable which can run without depending on a system Python. What's the best way of doing this? I previously would have used py2exe, but that seems not to have Python 3 support. I have heard good things about bbfreeze, but the author has stated that he has no intention of supporting Python 3 just yet. I've tried cx_Freeze, but I've hit a number of niggly problems which make me think it's not quite suitable (I've reported some of them on the cx_Freeze mailing list, but it seems pretty quiet - no real response). That leaves me wondering if there's another option, or whether I should just roll my own. if I zip up the stdlib, and my virtualenv site-packages, and then put them plus the various Python DLLs in a directory, copy my script in, and write a small EXE to set PYTHONHOME and run Py_Main with my script as argument, that should do. But it seems a bit laborious :-( Is that really the best way? Things I care about: - Easy to package up a script - Works with dependencies in a virtualenv - Completely isolated from system Python (not even leaving directories on sys.path, so I can do basic tests without having to create a clean system with no Python installed). Things I don't (really) care about: - Stripping ununsed modules (although I'd like to omit "big" parts of the stdlib that aren't used - tkinter and test come to mind) - Space (the full stdlib is only 30M including pyc files, after all) Any suggestions gratefully accepted :-) Paul. -- http://mail.python.org/mailman/listinfo/python-list
Instrumenting a class to see how it is used
I'm trying to reverse-engineer some pretty complex code. One thing that would help me a lot is if I could instrument a key class, so that I'd get a report of when and how each method was called and any properties or attributes were accessed during a typical run. I could do this relatively easily by just adding print calls to each method/attribute, but I was wondering - is there a library that does this sort of wrapping already? I tried writing my own but got bogged down in infinite recursion in _getattribute__ and couldn't see an easy way out. If anyone has any suggestions, I'd be interested. Thanks, Paul. -- http://mail.python.org/mailman/listinfo/python-list
Simple board game GUI framework
I'm doing some training for a colleague on Python, and I want to look at a bit of object orientation. For that, I'm thinking of a small project to write a series of classes simulating objects moving round on a chess-style board of squares. I want to concentrate on writing the classes and their behaviour, and not on display issues, but I would like it if the resulting program was reasonably interesting. To that end, I was thinking of putting together a frontend that displayed the objects moving round on a board (rather than, for example, just printing out lists of co-ordinates). I'd build the frontend, then my student could write the object classes and drop them into the framework. My problem is that I've never written any sort of game code for Python, which is basically what this is. And I don't have a lot of time to develop something. So I was wondering - are there any ready-made examples of the sort of driver I'm thinking of? Something like a framework for a Chess or Othello game, but with the actual game logic isolated so I could easily rip it out and replace it with my own. I've done some searching around, but most of the examples I've seen seem to have the display and game logic intermingled (at least to my untrained eye). Any suggestions? If not, I guess I'll just have to write my own. I'm sure I could - it's just that I don't want my training to be messed up because of bugs in my code... Thanks, Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: People choosing Python 3
On 11 September 2017 at 13:07, Chris Angelico wrote: > Fortunately, it's not that hard to type "python3" all the time. OS > distributions can progressively shift to using that name, and then > eventually not ship a Py2 until/unless something depends on it, all > without losing backward compatibility. My main objections to needing to type "python3" are: * It perpetuates the illusion that Python 3 isn't the "real" Python, and creates a feedback loop that makes it harder to persuade people that we're ready to make Python 3 the default. * It makes it harder to write cross-platform instructions that encompass Windows, which doesn't have a "python3" executable. But both of these are weak arguments and as usual, practicality beats purity. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple board game GUI framework
On 11 September 2017 at 13:13, Stefan Ram wrote: > Paul Moore writes: >>write a series of classes simulating objects > > I'd say "write classes for objects". Yeah, that's just me not being precise in my mail. Sorry. >>objects moving round on a chess-style board of squares > > This seems to follow the recommendation to model > objects after real-world entities. > > I prefer another approach when I do not have experience with > a type of program: I start to write the program "procedurally". We've been doing that - the issue is that we don't have sufficiently large real-world examples to make transitioning to objects a natural requirement. And yes, I know you're going to say "don't teach stuff the student doesn't actually need yet", but in this particular context I'm specifically being asked by the student (it's a one-to-one environment) to explain classes and objects, because he's encountering the ideas in other places. And I want to do so in a practical context, even if that practical context is artificial. >> but I would like it if the resulting program >>was reasonably interesting. > > »Interesting«, for me, is too vague and subjective. OK. Replace that with "I think my student would find it motivating to see a GUI style of behaviour, even if he had to take the implementation of that part of the program on faith". He's used to the idea of writing plugin code that fits into a framework, so this would be a familiar idea to him. >>I'd build the frontend, then my student could write the object classes >>and drop them into the framework. > > When the students are not yet able to write the whole > program themselves, it might make sense to write a part of > the program for them (the frontend) and have them supply the > rest. > > But the frontend is a teacher-supplied library (TSL), and to > write the rest of the program, the students have to learn the > interface of the TSL and then write code for the TSL. Agreed - but as I say, in my specific context I don't think this will be a problem (and I'm confident in my ability to clearly explain the difference between "you need to do this because that's what the framework expects" and "you need to do this because this is how you write a class"). > In my teaching, I avoid providing TSLs for my course > participants and have them learn the TSLs because I believe > that the standard distribution of Python (or Tkinter or > Pygame if you use on of those) alreadu has more than enough > libraries in them, and students should learn the standard > libraries and not additional teacher-supplied libraries. My student has told me that he would like to understand classes so that he can better understand the logic behind the class-based features in the stdlib. That's why I'm trying to find a useful, understandable, example to work with. >>My problem is that I've never written any sort of game code for >>Python, which is basically what this is. > > Get proficient first, then teach. I'll assume you don't mean that to be as critical of me as it sounds. I have no intention of trying to teach anyone "how to write a GUI program" or "how to use pygame". Any more than I'm trying to teach how the Python interpreter works. I'm simply trying to find (or build) an environment that helps me explain the concepts that I *am* trying to teach better than a command line REPL can do. > And as I said, I would prefer to teach the standard > frameworks and libraries that are distributed with the > standard distribution of Python before I teach additional > frameworks. As I said, I've been doing that, but need to help the student understand classes to give them a better understanding of why the stdlib is designed the way it is. > Ok, if you teach at a gaming academy of when the title > of the class contains the word "game", then you might have > to teach game programming, but in this case you should > really become proficient in it first. Well, obviously. I'm not sure why you think I'd consider it otherwise :-( Thank you for your comments, but clearly you have a very different environment and/or set of students than I have. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple board game GUI framework
On 11 September 2017 at 14:52, Christopher Reimer wrote: >> On Sep 11, 2017, at 3:58 AM, Paul Moore wrote: >> >> I'm doing some training for a colleague on Python, and I want to look >> at a bit of object orientation. For that, I'm thinking of a small >> project to write a series of classes simulating objects moving round >> on a chess-style board of squares. > > I started something similar to this and didn't get far. I wrote a base class > called Piece that had common attributes (I.e., color and position) and > abstract methods (i.e., move). From the base class I derived all the piece > types. That's the easy part. > > The board is a bit tricky, depending on how you set it up. The board of 64 > squares could be a list, a dictionary or a class. I went with a Board class > that used a coordinate system (i.e., bottom row first square was (0, 0) and > top row last square (7, 7)) and kept track of everything on the board. Thanks for the information. That's more or less the sort of thing I was thinking of. In fact, from a bit more browsing, I found another way of approaching the problem - rather than using pygame, it turns out to be pretty easy to do this in tkinter. The following code is basically the core of what I need: import tkinter as tk def create_board(root): board = {} for r in range(8): for c in range(8): lbl = tk.Button(bg="white", text=" ", font=("Consolas", 12)) lbl.grid(row=r, column=c) board[r,c] = lbl return board root = tk.Tk() board = create_board(root) root.mainloop() That creates an 8x8 grid of white buttons. With this, I can make a button red simply by doing board[3,2]["bg"] = "red" That's really all I need. With that I can place objects on the grid by asking them for their colour and x/y co-ordinates. Add a bit of driver logic, and I have a display system. We can then spend the time working on how we add business logic to the classes (movement, collision detection, etc...) I really need to spend some time looking into tkinter. I very rarely think of it when developing code, and yet whenever I do it's amazingly easy to put together a solution quickly and easily. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: People choosing Python 3
On 11 September 2017 at 15:53, Dennis Lee Bieber wrote: > > As for Windows itself... I use the ActiveState installers and see: > > Directory of c:\Python35 > > > 06/26/2017 07:22 PM41,240 python.exe > 06/26/2017 07:22 PM41,240 python3.5.exe > 06/26/2017 07:18 PM50,688 python3.dll > 06/26/2017 07:22 PM41,240 python3.exe > 06/26/2017 07:18 PM 3,935,744 python35.dll > 06/26/2017 07:50 PM24,344 pythonservice.exe > 06/26/2017 07:22 PM41,240 pythonw.exe Interesting. I didn't realise ActiveState did that. The python.org installers don't ship with python3.exe or python3.5.exe. And yes, I know that the Windows installers don't put Python on PATH by default. I'm assuming the user has added Python to his PATH (people using command line languages on Windows usually know how to do that). And I also know that a better option on Windows is to use the "py" launcher anyway. I did say it was a weak argument :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple board game GUI framework
On 11 September 2017 at 16:32, Dennis Lee Bieber wrote: > This leads to a subtle question... If the focus strictly on OOP, or do > you intend to supply some precursor OOAD stuff. OOP is just implementation > and usage, but without some understanding of OOAD the concepts may come > across as just magic. > > IE: classes are templates from which one instantiates objects; > instances of a class share methods, but each instance has its own state. > > Just doesn't help in figuring out what qualifies for a class vs instance, > what should be a method, and what is state. That's a very good point - and not one I'd really thought about (this isn't a formal training course, more of a set of mentoring and knowledge sharing sessions where I'm helping this guy get into "actual" programming rather than just hacking the odd VBA macro etc). I'll make sure I cover some of the design aspects in my discussion. >>OK. Replace that with "I think my student would find it motivating to >>see a GUI style of behaviour, even if he had to take the >>implementation of that part of the program on faith". He's used to the >>idea of writing plugin code that fits into a framework, so this would >>be a familiar idea to him. >> > Unless the "game" is going to be playing Chess (in which case you are > looking at way more than an intro to OOP), the GUI comes down to a grid of > squares, sprites/icons for the pieces, and a way to select/move the > piece... Yep, that's about it. But the point is, that's the framework, not what I actually want to get him implementing. > And the only logic left to implement would be validation of the > moves, and tests for capture when one moves into an occupied square. Not > really that much left for the student. I'm not looking at actually implementing chess. The idea was prompted by a programming exercise my son was given, that was about programming a series of classes modelling robots that know their position on a grid, and when told to move, can do so according to certain rules. One moves in a straight line till it hits the edge, one moves in a random direction, some bounce when they hit an obstacle and some just stop, etc. The idea is to demonstrate classes and inheritance to model common behaviours and objects holding state that the behaviour acts on. The original exercise (which used Java) just had the program print out the objects' co-ordinates at each step. I thought that visualising the results by actually showing the objects moving would be better. (And a quick discussion/demo with the guy I'm training showed me I'm right - his reaction was "wow, that looks really impressive" :-)) > Again, it sounds more like you need a language agnostic discussion of > OOAD -- not language specific OOP. Mostly agreed. But we have a tendency to spiral off into pure theory far too easily - and then my student doesn't remember what we covered because it wasn't grounded in anything practical. So I want to have a practical (and better still, visual) example to keep us focused. Thanks for the comments, Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: The Incredible Growth of Python (stackoverflow.blog)
On 12 September 2017 at 13:47, Leam Hall wrote: > A few months ago my manager asked about what direction I recommended for the > team. I'm the opinionated old guy who is new to this team. At the time I was > really enjoying Ruby; just so dang fun! > > I told my manager that we should use python. It is the best choice for the > team since we're on RHEL 6. Ruby wasn't on the machines but Python 2.6.6 is. > Any code I write that is python 2.6.6 compatible should run on every > machine. > > My answer meant I had to re-direct personal time and attention so I could > help the team move forward. There are certain things I can do; learn to code > better, write more tests, and figure out OOP. Some things I can't do; > changing the supported python version is on that list. > > Python is the right choice for a lot of use cases. Python 3 is the right > choice for a large sub-set of those use cases. Python 2 is the best choice > for a much smaller subset. Sounds like a very reasonable decision - I'm in a similar situation at times, and I agree with your recommendation. Python's a great tool, and if you like Ruby you should find it really easy to get into. As you say, if Ruby isn't available on the machines you're working with, the hurdle of getting it installed is likely a real blocker. Having Python installed makes it a good choice - and sticking with the installed version is definitely correct, otherwise you're no better off than you were with a language that's not installed by default. One thing you will have to deal with is that there's a lot less support available for Python 2.6 these days - most developers working with Python 2 will use 2.7, and new developers will typically pick Python 3 if at all possible. For a lot of things, you're relying on community support, which does mean you are "stuck" with what people are enthusiastic about. But the good news is that most advice you'll get is transferrable back to Python 2.6 (with a little care, particularly if it was originally for Python 3). And it's important to remember that community support is just that - individuals, offering help simply because they love Python. And those individuals are typically (in most communities, not just Python) early adopters, and strongly prefer working with the latest versions. The biggest hurdle you may hit is that 3rd party libraries are starting to drop support of Python 2.6. I don't know if you expect to use libraries from PyPI - in my environment, the systems that are locked to Python 2.6 are typically not connected to the internet, so non-stdlib code is generally not accessible - if that's the case for you this won't be an issue. Unfortunately, there's not much you can do about that - it's just one of the issues of working with older, unsupported versions. But a big plus with Python is that the stdlib is very comprehensive (less so with 2.6 than 3.6, but still very good in 2.6). So where you'd need to rely on external libraries for other languages, you can do an awful lot with a base 2.6 install. That's a big selling point in a locked down environment. Anyway, I'm not sure there's much specific here. But thanks for taking the time to explain your situation, which hopefully will act as a reminder that not everyone trying to promote Python has a clean slate to work with. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] beginning to code
On 12 September 2017 at 16:03, Rick Johnson wrote: > Chris Angelico wrote: >> Rick Johnson wrote: >> > Ruby: >> > farray = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length >> > >> > Python: >> > flist = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = len(set(map(lambda f:int(f), flist))) >> >> Python: >> >> floats = [1.5, 1.9, 2.0, 1.0] >> unique_integers = len(set(int(f) for f in floats)) >> >> or: >> >> unique_integers = len(set(map(int, floats)) >> >> If you're going to use Python, at least use it right. > > Okay, you've replaced my map function with an implicit list > comprehension (aka: generator expression)... so how is > either more "right" than the other? What is your > justification that your example is "right", and mine is not? > > (1) Is is a speed issue? Then prove it. > > (2) Is it a readability issue? If so, then that's an opinion > _you_ get to have. > > (3) Is a matter of "python purity"? If so, then map should be > removed from the language. And don't forget to remove reduce > and filter while you're at it. And then, you may want to > grab a shield, because the functional fanboys will be all > over you like white on rice! > > (4) Something else...? Ignoring stylistic choices (variable naming, map vs generator) then for me the key distinction here is "lambda f: int(f)" vs just "int". Python's callables (of which the integer constructor int is one) are first class objects, so you should just pass them directly. Creating an anonymous function using lambda that just calls int is slower, harder to read, and less natural. The lambda is a direct translation of the Ruby "|f| f.to_i()" - I don't know if Ruby lacks a built in "convert to integer" function - maybe it does because it takes the "everything is an object" philosophy much further than Python does, but that's where "this code was translated from another language" shows. Using map vs comprehensions is mostly a stylistic choice. Python programmers will typically choose a comprehension, so that style looks more idiomatic, but the map is not wrong. I haven't tested which is faster - I can't imagine it would make much practical difference in a real program. Readability is certainly a personal choice - but writing code that looks natural to other users of the language is an element of readability (not the only one, but it is one). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] beginning to code
On 12 September 2017 at 18:52, Rick Johnson wrote: > In any event, i believe my point -- that complex statements > in Ruby follow a more intuitive left-to-right comprehension > flow, whereas Python, which due to a reliance on built-in > functions as opposed to Object methods is directly > responsible for our code being littered with these less > intuitive nested function calls -- remains a valid point. Hardly. As you said to Chris, that's an opinion that you get to have - but trying to claim that your opinion is anything other than that (just an opinion) is pointless. > Feel free to offer a better solution if you like. INADA > Naoki offered a good solution for Python3 folks, but AFAIK, > set comprehensions are not avialable as a backported "future > feature" for Python2 folks. And surely not for Python1 > folks. So what? What's the point in comparing Ruby with years-out-of-date Python? At this point you're clearly just looking for an argument, so I'll give up on this thread. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple board game GUI framework
On 13 September 2017 at 17:05, Ian Kelly wrote: > On Tue, Sep 12, 2017 at 10:39 PM, Rick Johnson > wrote: >>> > board[r,c] = lbl >> >> Dude, that tuple is naked! And nudity in public places is >> not cool; unless of course your code is a Ms. America model, >> or it resides in a nudist colony (Hey, don't forget your >> "sitting towel"!), which obviously is not true in either >> case. ;-) Try this instead: >> >> board[(r,c)] = lbl >> >> There. And now, and in more ways than one, we have defined some >> bondaries. > > It's not naked. It has the square brackets around it, making the > parentheses clearly redundant. I use constructions like "board[r, c]" > all the time and I don't see a style problem with it. > > Now, as to not having a space after the comma, that's just sinful. Ha, by including that line I managed to distract everyone from how bad the *rest* of the code was! My plan worked! Bwahahaha :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Unicode (was: Old Man Yells At Cloud)
On 17 September 2017 at 12:38, Leam Hall wrote: > On 09/17/2017 07:25 AM, Steve D'Aprano wrote: >> >> On Sun, 17 Sep 2017 08:03 pm, Leam Hall wrote: >> >>> I'm still trying to figure out how to convert a string to unicode in >>> Python 2. >> >> >> >> A Python 2 string is a string of bytes, so you need to know what encoding >> they >> are in. Let's assume you got them from a source using UTF-8. Then you >> would do: >> >> mystring.decode('utf-8') >> >> and it will return a Unicode string of "code points" (think: more or less >> characters). > > > > Still trying to keep this Py2 and Py3 compatible. > > The Py2 error is: > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' > in position 8: ordinal not in range(128) > > even when the string is manually converted: > name= unicode(self.name) > > Same sort of issue with: > name= self.name.decode('utf-8') > > > Py3 doesn't like either version. Your string is likely not UTF-8 with a character \xf6 in it. Maybe it's latin-1? The key here is there's no way for Python (or any program) to know the encoding of the byte string, so you have to tell it. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: speech_to_text python command not working
On 18 September 2017 at 09:03, pizza python wrote: > Your error occurs because what the "external service" has delivered > it not what "speech-to-text" has expected. More precisely, > "speech-to-text" has excepted as result a dict with a "results" key -- > but this is missing (likely because some input is wrong or there > is a version mismatch between your "speech-to-text" and the "external > service"). > > >Someone else also thought there is a version mismatch between the >"speech-to-text" and the "external service". The external service has been >update four times since the "speech-to-text" library was put together. So it's pretty likely you need a new version of the "speech-to-text" library. > I expect that the "data" mentioned in the traceback above contains > some clues for what went wrong. I would use the Python debugger > to investigate along these lines. As you are not yourself a Python > programmer, find one in your region to support you. > > >Could someone kindly advise how to use "the Python debugger"? https://docs.python.org/3.6/library/pdb.html - but I would reiterate the advice that if you're not a programmer, you should get someone who is to assist you with this, as the debugger will not be easy to use without programming experience (and fixing the problem even more so). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: speech_to_text python command not working
With that information, my guess would be that the way the web service reports errors has changed, and the Python library is failing to handle errors nicely for you, but the basic functionality still works. So that's somewhat good news, as you can at least handle anything that *would* work, even if it's going to be hard to understand the reason for failures without a friendly message like "File too big"... On 18 September 2017 at 10:09, pizza python wrote: >Hi all. I tried the same command with a different, smaller file. This file >is a 90-kilobyte ogg file. The other one was a 26-megabyte ogg file. > >Wtih this smaller file, there was no error. > > > speech_to_text -u myUsername -p myPassword -f html -i audio-file.ogg >transcript.html >Starting Upload. > > [===] >100% >Upload finished. Waiting for Transcript >Speech > Text finished. > > >In the same folder as the ogg file was an html file with the transcript. >So I guess the python command works some times. I'm still not sure if it >just doesn't work on large files. > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] beginning to code
On 18 September 2017 at 14:30, Antoon Pardon wrote: > Well that you reduce an object to a boolean value is not obvious to > begin with. A TypeError because you are treating a non-boolean as > a boolean would have been more obvious to me. More obvious, possibly - that's essentially a matter of what people are used to, and a measure of personal opinion. More useful? Unlikely. The practical examples I've seen of languages like Python that implicitly convert non-boolean values to boolean, and languages that don't (and raise an error if a non-boolean is supplied to an if statement) suggest to me that implicit conversion is highly useful. I certainly use it in my code (although in my view it's perfectly "obvious", so I may use constructs that you would find non-obvious). > A second thought is that it isn't obvious that empty strings, lists ... > should be thought of as falsy. Sometimes I am treating a stream of > values/objects and when I ask for the next available items, i get > a string/list. An empty string/list in that context would mean that > nothing was available, but it is possible that more will be available > later and so could be treated just like a non-empty list/string. We can argue over the precise rules as to *what* boolean values Python chooses to take particular non-boolean values as meaning. I'm not going to have a blazing row over whether an empty string should be true or false. But equally, I'm not going to mount a campaign to change it. It's just not that important to me. If you want an argument worth having, go argue with the Perl people about the fact that "0" (the 1-character string containing a zero) is false in Perl: > perl -e "print qq'a non-empty string that is false\n' if not '0';" a non-empty string that is false Given this sort of silliness, I'm perfectly OK with the choices Python made :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"
On 20 September 2017 at 13:58, alister via Python-list wrote: > On Tue, 19 Sep 2017 14:40:17 -0400, leam hall wrote: > >> On Tue, Sep 19, 2017 at 2:37 PM, Stephan Houben < >> stephan...@gmail.com.invalid> wrote: >> >>> Op 2017-09-19, Steven D'Aprano schreef >> pearwood.info>: >>> >>> > There is a significant chunk of the Python community for whom "just >>> > pip install it" is not easy, legal or even possible. For them, if its >>> > not in the standard library, it might as well not even exist. >>> >>> But numpy *is* in the standard library, provided you download the >>> correct version of Python, namely the one from: >>> >>> https://python-xy.github.io/ >>> >>> Stephan >>> >>> >> Many of us can't pip install; it's in the OS supplied vendor repo or it >> doesn't go on the machines. >> >> Leam > > dnf install > or > apt_get install > > most of the mainstream modules seem to be there (certainly numpy) You're missing the point. A significant number of Python users work on systems where: 1. They have no admin rights 2. Their corporate or other policies prohibit installing 3rd party software without approval that is typically difficult or impossible to get 3. Quite possibly the system has no network access outside of the local intranet 4. The system admins may not be able or willing to upgrade or otherwise modify the system Python Writing code that works only with stdlib modules is basically the only option in such environments. Having said that, I don't advocate that everything be in the stdlib because of this. A lot of things (such as numpy) belong as 3rd party packages. But that doesn't mean that "get XYZ off PyPI" (or "install XYZ alternative Python distribution/version") is a viable solution to every problem. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: How does CPython build it's NEWS or changelog?
On 21 September 2017 at 09:59, Hartmut Goebel wrote: > Hello, > > I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for this? Is there some documentation, maybe a > mailingslist-diskussion or a but-report? There's a tool "blurb" (available from PyPI) used for this. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: How to ingore "AttributeError: exception
On 22 September 2017 at 10:05, Thomas Jollans wrote: > On 2017-09-22 10:55, Ganesh Pal wrote: >> I have two possible values for Z_block in the block code i.e >> disk_object.data.data.di_data[0] or block.data.data.di_data.data[0][0] >> >> >> def get_block(): >> ''' Get Z block '' >> >> if block.data.data.di_data.data[0][0] is not None: >> Z_block = block.data.data.di_data.data[0][0] >> >> else: >> Z_block = disk_object.data.data.di_data[0] >> >> if not Z_block: >> return False >> >> return Z_block >> >> >> >> >> I have a problem with if and else satement i.e if IF codition fails the >> code would exit with "AttributeError: 'list' object has no attribute >> 'data' " error >> >> Any suggestion on how this can be handled better , Will ignoring the >> exceptions in try -except with pass be good or are there easier ways ) , >> >> >> try: >> Z_block = block.data.data.di_data.data[0][0]except AttributeError as e: >> >> pass > > > > try: > return self.some.attribute.or.another > except AttributeError: > return DEFAULT_VALUE > > is a perfectly good pattern to use. getattr(obj, 'attr_name', DEFAULT_VALUE) may also be useful, although if more than one of the attribute lookups in the chain you show could fail, then catching the exception is probably simpler. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Old Man Yells At Cloud
On 23 September 2017 at 12:37, Steve D'Aprano wrote: > 95% of Python is unchanged from Python 2 to 3. 95% of the remaining is a > trivial > renaming or other change which can be mechanically translated using a tool > like > 2to3. Only the remaining 5% of 5% is actually tricky to migrate. If your code > base is full of things relying on that 5% of 5%, then you'll struggle. > Otherwise, is probably much easier than people expect. And in my experience, one of the worst difficulties is the transition to "clean" Unicode handling. I've seen many Python 2 codebases that mostly-work, either by assuming often-but-not-always-true things like "Everyone uses UTF-8", or "subprocesses always use the same encoding as my code" and then introduce "fixes" by tactical re-encoding rather than redesigning the code to "decode at the boundaries" - because it's quicker to do so, and everyone has deadlines. In those cases, the Python 3 transition can be hard, not because there's a lot of complexity to writing Python 3 compatible code, but because Python 3 has a stricter separation between bytes and (Unicode) strings, and doesn't support sloppy practices that Python 2 lets you get away with. You *can* write Unicode-clean code in Python 2 (and then the transition is easy) but many people don't, and that's when things get difficult. The worst cases here are people who know how to write good Unicode-safe code, and do so in Python 2, but using a different approach than the one Python 3 takes. Those people put effort into writing correct code, and then have to change that, *just* for the transition - they don't get the correctness benefit that others do. (I should also point out that writing Unicode-safe code is hard, from a *design* perspective, because an awful lot of data comes to you without a known encoding - text files, for example, or the output of a subprocess. Sometimes you *have* to guess, or make assumptions, and Python 3 tends to force you to make those assumptions explicit. Ironically, it's often the better coders that find this hard, as they are the ones who worry about error handling, or configuration options, rather than just picking a value and moving on). Paul -- https://mail.python.org/mailman/listinfo/python-list
Looking for an algorithm - calculate ingredients for a set of recipes
I'm trying to work out a good algorithm to code a calculation I need to do. I can see brute force ways of handling the problem, but I keep getting bogged down in details, and the question seems like it's something that should have been solved plenty of times in the past, I just don't know where to look. The basic problem is that I'm trying to model a set of recipes, and calculate the amounts of base ingredients needed to produce what I require. This is actually for calculating production requirements in Minecraft, so I have recipes of the form: 1 tank = 4 bars, 4 iron, 1 glass 16 bars = 6 iron 1 chassis = 4 bars, 4 iron, 1 capacitor 1 alloy smelter = 1 chassis, 1 cauldron, 3 furnace, 4 iron 1 cauldron = 7 iron If I want to make 1 alloy smelter and 2 tanks, I need: (alloy smelter) 1 chassis 4 bars 4 iron 1 capacitor 1 cauldron 7 iron 3 furnace 4 iron (tanks) 8 bars 8 iron 2 glass Total iron (for example) = 23, plus 6 (enough for 12 bars - note that we have to make bars in batches of 16) = 29. I can model the recipes as basically a graph (a DAG). Calculating the amounts isn't too hard if we ignore the batch crafting aspect, but I also need to cater for the possibility of "I need 3 of X and 4 of Y, but I need 2 extra X to craft each Y, so I need a total of 11 X). So there's an element of feedback involved as well. I can probably come up with a viable approach given some time, but this feels like the sort of calculation that comes up a lot (basically any "recipe" based exercise - cooking, manufacturing, etc) and I feel as if I'm at risk of reinventing the wheel, which I could avoid if I only knew what the techniques I need are called. Can anyone suggest any pointers? Thanks, Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Looking for an algorithm - calculate ingredients for a set of recipes
On 25 September 2017 at 14:23, Ian Kelly wrote: > You have a DAG, so you can sort it topologically. Then you can process > it in that order so that everything that uses X will be processed > before X so that when you get to X you'll know exactly how much of it > you need and you don't have to worry about "feedback". For actual > production, run through it in the opposite order so that you'll > produce all your precursors before the things that require them. Hmm, yes that makes sense. I was thinking of a topological sort in the other direction (ingredient before product) and that way round doesn't work. For some reason, when thinking about topological sorts, I tend to get fixated on one direction and forget they are actually reversible... Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Looking for an algorithm - calculate ingredients for a set of recipes
On 25 September 2017 at 15:20, Paul Moore wrote: > On 25 September 2017 at 14:23, Ian Kelly wrote: >> You have a DAG, so you can sort it topologically. Then you can process >> it in that order so that everything that uses X will be processed >> before X so that when you get to X you'll know exactly how much of it >> you need and you don't have to worry about "feedback". For actual >> production, run through it in the opposite order so that you'll >> produce all your precursors before the things that require them. > > Hmm, yes that makes sense. I was thinking of a topological sort in the > other direction (ingredient before product) and that way round doesn't > work. For some reason, when thinking about topological sorts, I tend > to get fixated on one direction and forget they are actually > reversible... Thank you. With that hint, the problem turned out to be remarkably simple. If anyone is interested, here's the basic approach: import networkx as nx G = nx.DiGraph() G.add_edge("Tank", "Bars", qty=4) G.add_edge("Tank", "Iron", qty=4) G.add_edge("Tank", "Glass", qty=1) G.add_edge("Bars", "Iron", qty=6, batch=16) G.add_edge("Chassis", "Bars", qty=4) G.add_edge("Chassis", "Iron", qty=4) G.add_edge("Chassis", "Capacitor", qty=1) G.add_edge("Alloy Smelter", "Chassis", qty=1) G.add_edge("Alloy Smelter", "Cauldron", qty=1) G.add_edge("Alloy Smelter", "Furnace", qty=3) G.add_edge("Alloy Smelter", "Iron", qty=4) G.add_edge("Cauldron", "Iron", qty=7) from collections import defaultdict need = defaultdict(int) need["Alloy Smelter"] = 1 need["Tank"] = 2 import math for item in nx.topological_sort(G): for ingredient in G[item]: edge = G[item][ingredient] if "batch" in edge: # Round up batches = math.ceil(need[item] / edge["batch"]) else: batches = need[item] need[ingredient] += batches * G[item][ingredient]["qty"] print(need) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: TypeError with map with no len()
You're using Python 3, and I suspect that you're working from instructions that assume Python 2. In Python 3, the result of map() is a generator, not a list (which is what Python 2's map returned). In order to get an actual list (which appears to be what you need for your plot call) you just need to call the list constructor: y1 = list(map(math.sin, math.pi*t)) Although given that you're using numpy, it may be that there's a more idiomatic numpy way of doing this. I'm not a numpy expert though, so I can't help on that. Paul On 25 September 2017 at 17:44, john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using Python > 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) > plt.plot(t,y1) > > However, at this point, I get a TypeError that says > > object of type 'map' has no len() > > In [6]: t > Out[6]: > array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , > 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, > 2.2, 2.3, 2.4]) > In [7]: y1 > Out[7]: > In [8]: math.pi*t > Out[8]: > array([ 0., 0.31415927, 0.62831853, 0.9424778 , 1.25663706, > 1.57079633, 1.88495559, 2.19911486, 2.51327412, 2.82743339, > 3.14159265, 3.45575192, 3.76991118, 4.08407045, 4.39822972, > 4.71238898, 5.02654825, 5.34070751, 5.65486678, 5.96902604, > 6.28318531, 6.59734457, 6.91150384, 7.2256631 , 7.53982237]) > > At the start of creating y1, it appears there is an array to iterate through > for the math.sin function used in map(), but y1 doesn't appear to be saving > any values. I expected y1 to hold a math.sin() output for each item in > math.pi*t, but it appears to be empty. Am I misunderstanding map()? Is there > something else I should be doing instead to populate y1? > > > John > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: auto installing dependencies with pip to run a python zip application ?
On 26 September 2017 at 19:47, Irmen de Jong wrote: > Any thoughts on this? Is it a good idea or something horrible? Has > someone attempted something like this before perhaps? When I've done this, I've bundled my dependencies in with my zipapp. Of course that's trickier if you have binary dependencies like pillow. What you could do is pip install your binary dependencies into a directory in $TEMP using --target, then add that directory to sys.path. Probably easier than building a full virtualenv. Bundle pip with your app if you can't assume your users will have pip available. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: auto installing dependencies with pip to run a python zip application ?
On 26 September 2017 at 23:48, Irmen de Jong wrote: > On 09/26/2017 10:49 PM, Paul Moore wrote: >> On 26 September 2017 at 19:47, Irmen de Jong wrote: >>> Any thoughts on this? Is it a good idea or something horrible? Has >>> someone attempted something like this before perhaps? >> >> When I've done this, I've bundled my dependencies in with my zipapp. >> Of course that's trickier if you have binary dependencies like pillow. > > Yeah I've considered that for a moment but I think sometimes you've also > got to deal with licensing issues. I'd rather avoid this. I'd assume you're simply bundling for convenience, but I agree that avoiding the treacherous waters of licensing is always a good idea ;-) >> What you could do is pip install your binary dependencies into a >> directory in $TEMP using --target, then add that directory to >> sys.path. Probably easier than building a full virtualenv. Bundle pip >> with your app if you can't assume your users will have pip available. > > Interesting idea, although like this wouldn't I have to download the > dependencies every time I launch my game? (unless I re-use the same > temporary directory every time) Ah, I'd assumed that's what you were doing with the virtualenv, I hadn't realised you were talking about a one-off setup step. Yeah, re-using a temporary directory doesn't buy you much compared to using a virtualenv (particularly if you can target versions of Python that have the built in venv module). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: auto installing dependencies with pip to run a python zip application ?
Are you aware of pipsi? If you do `pipsi install somepackage` it creates a new virtualenv in ~/.local/.venvs, populates it with somepackage and its dependencies, and then puts the entry point scripts for somepackage into ~/.local/bin. It may be a useful way of delivering your program, rather than building the virtualenv management in yourself. (On the other hand "download this file and run it" is a much easier installation process than "install pipsi, do pipsi install myprogram, then run the program", so it may not suit your use case...) Paul On 27 September 2017 at 19:03, Irmen de Jong wrote: > On 09/27/2017 09:50 AM, Paul Moore wrote: > >>>> What you could do is pip install your binary dependencies into a >>>> directory in $TEMP using --target, then add that directory to >>>> sys.path. Probably easier than building a full virtualenv. Bundle pip >>>> with your app if you can't assume your users will have pip available. >>> >>> Interesting idea, although like this wouldn't I have to download the >>> dependencies every time I launch my game? (unless I re-use the same >>> temporary directory every time) >> >> Ah, I'd assumed that's what you were doing with the virtualenv, I >> hadn't realised you were talking about a one-off setup step. Yeah, >> re-using a temporary directory doesn't buy you much compared to using >> a virtualenv (particularly if you can target versions of Python that >> have the built in venv module). > > Well, I was planning on using a fixed name/location for the virtualenv. > That way when you request pip to install the dependencies again at next > launch, it will detect them already satisfied and not download/reinstall > everything. I could even test for their existence first myself in my > application (which is what I'm already doing now, to give the user a > clear error message) and only invoke pip when a dependency is missing. > > > -irmen > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Beginners and experts (Batchelder blog post)
On 27 September 2017 at 17:41, leam hall wrote: > Hehe...I've been trying to figure out how to phrase a question. Knowing I'm > not the only one who gets frustrated really helps. > > I'm trying to learn to be a programmer. I can look at a book and read basic > code in a few languages but it would be unfair to hire myself out as a > programmer. I'm just not yet worth what it costs to pay my bills. You're already ahead of the game in wanting to be useful, rather than just knowing the jargon :-) However, I've always found that the biggest asset a programmer can have is the simple willingness to learn. "Programming" is far too broad a subject for anyone to know all about it, so being able (and willing!) to find things out, to look for and follow good practices, and to keep learning, is far more important than knowing the specifics of how to code a class definition. Most programmers work in teams, so you will likely be working with an existing code base for reference (even if you're not doing actual maintenance coding), so you'll have examples to work from anyway. > To move forward takes a plan and time bound goals. At least for us old > folks; we only have so much time left. I want to avoid retirement and just > work well until I keel over. > > I don't come from a CS background but as a Linux sysadmin. My current push > is OOP. Grady Booch's book on Analysis and Design is great and I've got the > GoF for right after that. I've been doing more testing but need to write > more tests. Writing code and starting to work with others on that code as > well. I haven't read Booch, but I've heard good things about it. The GoF is good, but a lot of the problem's it's addressing aren't really issues in Python. So be prepared to find that the solutions look a bit over-engineered from a Python perspective. The ideas are really useful, though. Keep in mind that in Python, OOP is just one option of many - it's a very useful approach for many problems, but it's not as all-embracing as people with a Java or C# background imply. In particular, Python uses a lot less subclassing than those languages (because duck typing is often more flexible). > The question is, what should a person "know" when hiring out as a > programmer? What is 'know" and what should be "known"? Specifically with > Python. With Python, I'd say that an appreciation of the available libraries is key - both what's in the stdlib, and what's available from PyPI. That's not to say you should memorise the standard library, but rather cultivate an approach of "hmm, I'm pretty sure I remember there being a library for that" and going to look. The best way of getting this is to actually work with code - you can start with doing coding projects of your own (it's *always* a good exercise to have a problem that interests you, and work on coding it - no matter what it is, you'll learn more about understanding requirements, testing, bug fixing, and practical programming by working on a project you care about than you'll ever get reading books) and/or you can look at existing open source projects that you're interested in, and offer help (there's always a bug tracker, and typically some simpler items - and you'll learn a lot from interacting with a larger project). Hope this helps, Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Spacing conventions
On 28 September 2017 at 06:56, Bill wrote: > Steve D'Aprano wrote: >> >> >> Similarly for break and continue. >> >>> I can still see their >>> use causing potential trouble in (really-long) real-world code. >> >> How so? >> >> Besides, if your code is "really long", you probably should factorise it >> into >> smaller, meaningful chunks. >> > > I worked in maintenance programming. You got the hand you were dealt! And > you weren't allowed to "improve" the code unless the customer contracted you > to do so. I maintained for-loops (containing for-loops)... hundreds of > lines long. Would you be searching for break or > continue? : ) I also work in maintenance. Agreed 100% that the sort of code you deal with is a nightmare. But the problem with that code is *not* break/continue, but the lack of structure and the fact that the code isn't properly broken into meaningful subunits. I'd rather not search for break/continue in such code, sure, but that's missing the point entirely. "Don't use break/continue in appallingly bad code" doesn't generalise to "don't use break/continue", but rather to "don't write appallingly bad code" :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: when is filter test applied?
My intuition is that the lambda creates a closure that captures the value of some_seq. If that value is mutable, and "modify some_seq" means "mutate the value", then I'd expect each element of seq to be tested against the value of some_seq that is current at the time the test occurs, i.e. when the entry is generated from the filter. You say that doesn't happen, so my intuition (and yours) seems to be wrong. Can you provide a reproducible test case? I'd be inclined to run that through dis.dis to see what bytecode was produced. Paul On 3 October 2017 at 16:08, Neal Becker wrote: > In the following code (python3): > > for rb in filter (lambda b : b in some_seq, seq): > ... some code that might modify some_seq > > I'm assuming that the test 'b in some_seq' is applied late, at the start of > each iteration (but it doesn't seem to be working that way in my real code), > so that if 'some_seq' is modified during a previous iteration the test is > correctly performed on the latest version of 'some_seq' at the start of each > iteration. Is this correct, and is this guaranteed? > > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: when is filter test applied?
On 3 October 2017 at 16:38, Neal Becker wrote: > I'm not certain that it isn't behaving as expected - my code is quite > complicated. OK, so I'd say the filtering would follow any changes made to some_seq - not because it's a documented guarantee as such, but simply as a consequence of the behaviour of generators and closures. I'd tend to steer clear of code that relied on that behaviour in practice, as I think it's likely to be hard to understand/maintain, but I'm aware that reality's never quite that simple :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Good virtualenv and packaging tutorials for beginner?
On 4 October 2017 at 13:30, leam hall wrote: > On Wed, Oct 4, 2017 at 7:15 AM, Ben Finney > wrote: > >> Leam Hall writes: >> >> > Folks on IRC have suggested using virtualenv to test code under >> > different python versions. Sadly, I've not found a virtualenv tutorial >> > I understand. Anyone have a link to a good one? >> >> The Python Packaging Authority has a guide >> https://packaging.python.org/tutorials/installing- >> packages/#creating-virtual-environments> >> which seems good to me. >> >> The standard library documentation for the ‘venv’ library >> https://docs.python.org/3/library/venv.html> is essential. >> >> > The next step will be to figure out how to package a project; a good >> > tutorial URL would be appreciated on that, too. >> >> Follow the documentation maintained by the Python Packaging Authority >> https://packaging.python.org/>. >> >> > Ben, thanks! I'm off to print and study... Leam - if the guide is difficult to follow, feel free to ask here, or raise issues on the project tracker at https://github.com/pypa/python-packaging-user-guide/. Most of us working on packaging are way too involved in the details to know how it really feels to a newcomer to be faced with all this stuff, so if you have any comments (or even better, suggestions as to how we could improve things) that would be immensely valuable. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: How best to initialize in unit tests?
I've not had this problem myself, but py.test has the idea of "autouse fixtures" which would work for this situation. Define your setup call in a function, declare it with the pytest.fixture decorator with autouse=True, and it'll be run before every test. The declaration goes in a conftest.py file alongside your test files. I don't know if unittest or doctest has anything similar, but I suspect not (or at least not something as simple). Whether you're comfortable with the level of magic behaviour pytest has is probably something you'll have to decide for yourself (although I believe it does discover unittest and doctest tests, so you don't need to change all your tests over). There's an example of an autouse fixture in pip's test suite, although it's massively more complex than what you're describing, so don't be put off by the size of it :-) Paul On 4 October 2017 at 14:07, Skip Montanaro wrote: > Suppose you want to test a package (in the general sense of the word, > not necessarily a Python package). You probably have specific unit > tests, maybe some doctests scattered around in doc strings. Further, > suppose that package requires you call an initialize function of some > sort. Where does that go? I know about setUp and setUpClass methods in > unittest.TestCase. Is order of execution of doctests deterministic > across modules (say, when tests are run through nosetests)? > > In my case, I didn't know what order things would be called, so I > added a call to initialize() at the start of every doctest and added a > setUpClass class method to all my TestCase subclasses. Just in case. > It worked okay because my initialize function can be called multiple > times. What about situations where it can only be called once? Do you > have to define some sort of super_initialize() function for your tests > which guarantees that your initialize function is called precisely > once? > > This all seems rather messy. I'm open to better ways to do this, but > as I've only had one cup of coffee this morning, no spark of insight > has zapped my frontal cortex as yet. > > Thx, > > Skip > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: The "loop and a half"
On 4 October 2017 at 14:02, Robin Becker wrote: > On 04/10/2017 11:57, Rhodri James wrote: >> >> On 04/10/17 10:01, Robin Becker wrote: >>> >>> Given the prevalence of the loop and a half idea in python I wonder why >>> we don't have a "do" or "loop" statement to start loops without a test. >> >> >> See PEP 315. Guido's rejection note is here: >> https://mail.python.org/pipermail/python-ideas/2013-June/021610.html >> > seems fair enough; I suppose the cost is negligible or perhaps there's > peephole optimization for this common case. There is: >>> def f(): ... while True: ... pass ... >>> import dis >>> dis.dis(f) 2 0 SETUP_LOOP 4 (to 6) 3 >>2 JUMP_ABSOLUTE2 4 POP_BLOCK >>6 LOAD_CONST 0 (None) 8 RETURN_VALUE Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: newb question about @property
On 4 October 2017 at 16:03, bartc wrote: > No error. Some would perceive all this as an advantage, but it means you > can't just declare a lightweight struct or record 'Point' with exactly two > fields x and y. You have to use other solutions ('namedtuples' or whatever, > which probably are immutable so that don't work the same way). > > This is another example of neglecting the basics, but going for more > advanced, perhaps more sexy features instead. It's another example of a consistent design philosophy (highly dynamic classes) that you might not like - possibly even enough that Python isn't the best language for you. It's not an advantage or a disadvantage, just an approach. Many people like it, you may not. Specifically, yes you can't "just declare a lightweight struct or record with exactly two fields". Python doesn't enforce things like that, but leaves it to the programmer(s) to agree on (and follow) conventions in the code. This means that certain classes of error (e.g. mistyping an attribute name) can go unnoticed until later than in other languages, but conversely it means that things like monkeypatching of 3rd party code are possible. The popularity of Python is evidence that the flexibility this allows is useful to many people. Expecting Python to have the same design as other languages does a disservice to both Python and those other languages. There are trade-offs in these things, and Python's choices won't be the best in all circumstances. All we can really say is that they have turned out to be pretty useful and popular in many situations... Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Multithreaded compression/decompression library with python bindings?
On 4 October 2017 at 16:08, Steve D'Aprano wrote: > On Wed, 4 Oct 2017 08:19 pm, Thomas Nyberg wrote: > >> Hello, >> >> I was wondering if anyone here knew of any python libraries with >> interfaces similar to the bzip2 module which is also multithreaded in >> (de)compression? Something along the lines of (say) the pbip2 program >> but with bindings for python? > > pbip2? Never heard of it, and googling comes up with nothing relevant. > > Got a link? It's a typo. pbzip2 - a search found http://compression.ca/pbzip2/ but I don't know anything about it. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: The "loop and a half"
On 4 October 2017 at 16:35, Steve D'Aprano wrote: > I've been programming in Python for twenty years, and I don't think I have > ever once read from a file using a while loop. Twenty years isn't long enough :-) The pattern the OP is talking about was common in "Jackson Structured Programming" from back in the 1980s. At the time (from what I recall, it *was* 35+ years ago after all!), it was a reasonably elegant way of handling reading of data that's structured as header subheader body body subheader body body while maintaining per-section style subtotals (I believe this is referred to as a "break report" in certain business contexts). Nowadays, I wouldn't code such a report like that. Like you say, I'd use a custom iterator or something similar. Although getting the details and edge cases right of such a pattern is still a surprisingly tricky problem. So I guess it's a good "learning to program" exercise, but the "while loop with break part way through" pattern for solving it is not really what I'd want to see taught to beginning Python programmers... Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: newb question about @property
On 4 October 2017 at 17:02, Rhodri James wrote: > Actually you can: > class Point: > ... __slots__ = ("x", "y") > ... def __init__(self, x, y): > ... self.x = x > ... self.y = y > ... def __str__(self): > ... return "({0},{1})".format(self.x, self.y) > ... p = Point(3,4) print(p) > (3,4) print(p.x) > 3 p.x = 7 print(p) > (7,4) p.z = 2 > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'Point' object has no attribute 'z' > > I pretty much never bother to do this because (bart to the contrary) it > isn't useful if you're thinking in Pythonic terms, but it can be done pretty > easily. Good point. I'd forgotten that - like you say, it's not common to want to constrain things to this level in idiomatic Python code. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Constants [was Re: newb question about @property]
On 4 October 2017 at 17:15, Ian Kelly wrote: > On Wed, Oct 4, 2017 at 9:08 AM, Steve D'Aprano > wrote: >> But in large projects, especially those where you cannot trust every module >> in >> the project to obey the naming convention, I can see that this lack might >> contribute to the perception, if not the fact, of Python being a bit too >> unsafe for big projects. We have read-only attributes in classes, but not >> read-only names in modules. That makes me a little bit sad. > > Which brings up the point that you can hack it in if you want it. > > $ cat demo.py > import sys > > class DemoModule: > @property > def foo(self): > return 42 > > sys.modules['demo'] = DemoModule() > > $ python3 -c 'import demo; print(demo.foo); demo.foo = 14' > 42 > Traceback (most recent call last): > File "", line 1, in > AttributeError: can't set attribute I wonder - would the people who want "real constants" find the following confusing: >>> from demo import foo >>> foo = 14 >>> foo 14 It's fundamental to the way the import function works, and how names in Python behave, but I can see someone with a background in other languages with "real" constants thinking "but foo is a constant, and importing it stops it being a constant!" Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: stop/start windows services -python command
On 6 October 2017 at 04:52, Prabu T.S. wrote: > On Thursday, October 5, 2017 at 9:00:19 PM UTC-4, MRAB wrote: >> On 2017-10-06 01:37, Prabu T.S. wrote: >> > On Thursday, October 5, 2017 at 8:33:02 PM UTC-4, MRAB wrote: >> >> On 2017-10-05 23:32, Prabu T.S. wrote: >> >> > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: >> >> >> hello all,what is the command to stop and start windows services ? >> >> >> i can't install win32serviceutil bec am using latest python version. >> >> > >> >> > Please advice on this >> >> > >> >> Ask Google: windows services start stop command line >> > >> > asking for python. >> > >> Again, ask Google: windows services start stop python >> >> Those results talk about "win32serviceutil", which is not part of the >> standard library, but part of pywin32, which you can download. > > i tried pywin32, but its not compatible with python 3.6. Is there anyway i > can implement start and stop services in python 3.6 version. pywin32 *is* available for Python 3.6. Either from https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/ (a wininst installer, which is not compatible with pip but which nevertheless can be installed in your system Python) or from http://www.lfd.uci.edu/~gohlke/pythonlibs/ which hosts a lot of wheels for Windows,or as pypiwin32 from PyPI (https://pypi.python.org/pypi/pypiwin32/220). It's possible to find at least some of these via Google searches, too. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: why does memory consumption keep growing?
On 6 October 2017 at 06:51, Chris Angelico wrote: > Cloud computing is the answer. > > If you don't believe me, just watch the sky for a while - new clouds > get added without the sky turning off and on again. The sky reboots every 24 hours, and the maintenance window's about 8-12 hours. Not exactly high availability. But apparently in the arctic regions they are experimenting with a 24x7 version of the sky for short periods of the year... Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]
On 6 October 2017 at 09:36, Peter J. Holzer wrote: > On 2017-10-06 08:09, Steve D'Aprano wrote: >> What are the right ways for a Python script to detect these sorts of >> situations? >> >> (1) Standard input is coming from a pipe; >> >> (2) Stdin is being read from a file; >> >> (3) Stdin is coming from a human at a terminal; >> >> I get these. How did I do? >> >> >> # 1 detect input coming from a pipe. >> import sys >> import os >> from stat import S_ISFIFO >> if S_ISFIFO(os.fstat(0).st_mode): >> print("Reading from a pipe") >> >> >> # 2 detect input coming from a regular file. >> from stat import S_ISREG >> if S_ISREG(os.fstat(0).st_mode): >> print("Reading from a file.") >> >> # 3 detect a terminal, hopefully with a human typing at it >> if os.isatty(0): >> print("Oy noddy, wake up and type something, I'm waiting for you!") > > I'd do it the same way. > >> I feel a bit weird about using the magic constant 0 here. Is that guaranteed >> to be stdin on all platforms? > > It is guaranteed on POSIX compatible OSs. I think it is also guaranteed > on Windows, Don't know about VMS or the IBM OSs. All of these work on Windows, I just tested. Which surprised me, as I thought things like S_ISFIFO were Unix specific. Today I learned... (I'd probably still use sys.stdin.fileno() as it's more self-documenting). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]
On 6 October 2017 at 10:14, Marko Rauhamaa wrote: > Generally, you shouldn't condition the program too much on such > environmental details, although it is done. For example, the "ls" > command outputs the directory listing in a (colorful) multi-column > format when stdout is a terminal and in a (b/w) one-file-per-line format > otherwise. Agreed that any behaviour of the program should be explicitly controllable by command line arguments and/or configuration. But IMO, it's perfectly OK for the *default* behaviour to be affected by the environment, as long as that's done in a way that provides a good user experience. Of course, what constitutes a "good UX" is a judgement call... (Personally I think ls goes too far in how different it is in the interactive case, for example). Paul > > Since such guesswork often goes wrong, the program should provide > command-line options to specify the operating mode explicitly. The "ls" > command has "--color" and "--format". The "ssh" command has "-o > BatchMode=yes" and so on. > > Again, the Unix way is to preferably stay silent by default. If you want > the program to chat, there is "--verbose". > > > Marko > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]
On 6 October 2017 at 12:42, Chris Angelico wrote: > Generally, you should not have to worry about the behaviour of a > program being drastically different if you append "| cat" to the > command line. Which means you don't want TOO much difference between > interactive mode and non-interactive mode, which in turn limits the > extent of these changes to the defaults. It wants to be small changes > only. Everything else should be controlled with options, not magic. Yep. My real beef with ls is multi-column vs single-column. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]
On 6 October 2017 at 13:22, Steve D'Aprano wrote: >> Yep. My real beef with ls is multi-column vs single-column. >> Paul > > You don't think multiple columns in interactive mode is useful? I'm surprised, > because I find it invaluable. Interactively, I use ls -l 99.9% of the time. When I use raw ls, the column format is OK, but the fact that the number of columns varies depending on the filename length is really annoying (one really long filename can really mess the layout up). > I would hate for `ls` to default to printing everything in one long column. I > suppose I could define an alias, but then every time I'm on a different > computer or running as a different user, I'd end up with the annoying default > single column again. And that's precisely why carefully defining the defaults is both crucial and hard :-) I don't think the designers of ls necessarily got it wrong. But I'm one of the (small, presumably) group who find it sub-optimal. That's OK - you can't please all of the people all of the time and all that :-) What *really* bugs me is colour settings that default to dark blues on a black background. Someone, presumably an admin who set the system up, worked on a light-background system, and defined defaults that are good for them. And which are illegible for every single one of the actual users who have black-background ssh clients. Add the fact that I work on shared admin accounts, where setting non-default preferences is considered an antisocial act (even when they are "better" ;-)) and I spend my life squinting at screens, or typing "unalias ls" to remove the --color setting. Luckily (for everyone who has to listen to me rant), this is "just" annoyingly badly configured systems, and not baked in program defaults. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Introducing the "for" loop
On 6 October 2017 at 13:44, ROGER GRAYDON CHRISTMAN wrote: > Despite the documentation, I would still be tempted to say that range is a > function. > Taking duck-typing to the meta-level, every time I use range, I use its name > followed > by a pair of parentheses enclosing one to three parameters, and I get back an > immutable sequence object. It sure looks like a function to me. > > I would similarly say that map is a function, or an iterator generator I write > myself > with yield statements is a function, both of which also return sequences. > It is not clear to me what the difference really is between my conception > and the official definition -- is it a question about whether it returns a > first-class object? > > Or more simply, what is the clear and obvious distinction that I can give to > my > non-scientific laypeople about why range isn't a function, if it looks like > one? Technically, range (and the other examples you mentioned) is a "callable". The concept of a callable is closer to the intuitive meaning of "function" than the things Python technically calls functions. And most code accepts callables rather than functions (i.e., there's little if anything that rejects range because it's a callable not a function). Duck typing means that you can take class C: pass c = C() and replace it with class C_impl: pass def C(): return C_impl() c = C() and there's little or no difference. In the first, C is a class. In the second it's a (factory) function. You can tell the difference, via introspection. But it's unlikely you'd care in practice. As to the technical differences, you can use type() to tell: >>> def f(): pass ... >>> class F: pass ... >>> type(f) >>> type(F) >>> type(range) >>> type(map) >>> type(open) Note the last - built in functions are implemented in C, and behave slightly differently than *either* functions or classes. But you're unlikely to ever care. One example: >>> f.attr = 1 >>> open.attr = 1 Traceback (most recent call last): File "", line 1, in AttributeError: 'builtin_function_or_method' object has no attribute 'attr' functions defined in Python can have user-defined attributes, builtins can't. Embrace duck typing, and only care about what you can do, not what type of object you're doing it to ;-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: The "loop and a half"
On 6 October 2017 at 13:56, bartc wrote: > If you don't like the word 'crude', try 'lazy'. Take this example of the gcc > C compiler: > > > gcc -E program.c > > This preprocesses the code and shows the result. Typical programs will have > many thousands of lines of output, but it just dumps it to the console. You > /have/ to use '>' to use it practically (Windows doesn't really have a > working '|' system.) No you don't. Ignoring the fact that "windows doesn't really have a working '|' system" (which is an oversimplification, by the way) the following all work: Python: data = subprocess.check_output(["gcc", "-E", "program.c"]) Powershell: $x = (gcc -E program.c) cmd: for /f %i in ('gcc -E program.c') do ... If gcc -E wrote its output to a file, you'd have to read that file, manage the process of deleting it after use (and handle possible deletion of it if an error occurred), etc. Writing to stdout is very often a good design. Not always, but nothing is ever 100% black and white, but sufficiently often that building an OS based on the idea (Unix) was pretty successful :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: The "loop and a half"
On 8 October 2017 at 11:36, bartc wrote: > Frustrating for whom? Well, me as well as Steve, if we're counting votes for who finds your attitude frustrating... > It seems to me that it's pretty much everyone here who has an overbearing > sense of superiority in that everything that Unix or Linux does is a million > times better than anything else. As a Windows user, I would like to make it clear that your views don't in any way represent me. > Even with things like building applications (eg. trying to build CPython > from sources), they are designed from the ground up to be inextricably > linked to Linux scripts, utilities, makefiles, installation schemes, or > designed to work with the Linux-centric gcc C compiler. Then when they don't > work as well anywhere else, it's because Linux is so much better! No, it's > because they were non-portably designed around Linux and therefore designed > NOT to work well anywhere else. When developing scripts, applications, or any form of code, I use good ideas from anywhere, as I doubt that I have the monopoly on knowing the perfect way to write code. Some of those good ideas come from Unix-based systems. That's not "because Linux is so much better", it's because someone other than me had a good idea, and I acknowledge the fact. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: OT again sorry [Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]]
On 8 October 2017 at 17:43, Marko Rauhamaa wrote: > It is not at all easy for the Linux user to figure out what > configuration options there are, and which ones are intended for > end-user configuration. More and more, such tuning needs to be > done via systemd unit files (or applicable GUI facilities) and the > classical configuration files are deprecated. For example, how can a > programmer get a core file of a crashing program? Why, you need to use > the systemd-coredump service, of course: One of the things I liked about Debian many years ago when I played with Linux (when the options available were Debian, Red Hat, Slackware and SuSE and that was about it) was that they typically "fixed" the defaults of programs in the build options, so that there were almost no config files in the default install. That made it pretty easy for a user - you just set any extra options you want. With the other distros, they tended to make changes via config files, which was probably more transparent and easier to understand, but meant that a naive user like me couldn't tell what I was "allowed" to change (and by "allowed" I don't mean permission, more "if I change this, will I end up spending days trying to work out what weird interaction with other tools'expectations I just broke"). Sadly, those simpler days are long gone, and nowadays all Linux distros as far as I can see have a mass of predefined config (and the inevitable "config manager" tools to manage them). Not that I can complain about this, as a Windows user, but I do have fond memories of those simpler times :-) Obligatory xkcd: https://xkcd.com/297/ Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Python GUI application embedding a web browser - Options?
On 9 October 2017 at 04:25, wrote: > Did you find out the answer for that? Nothing much beyond the pointer to PyQt (which basically said "a lot of the info on the web is out of date" so I should check the latest docs). I didn't take it much further, though, as it was a hobby project and the learning curve for PyQt (any GUI framework, really) was a bit high for the amount of spare time I had at the time. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to globally set the print function separator?
On 9 October 2017 at 17:22, John Black wrote: > I want sep="" to be the default without having to specify it every time I > call print. Is that possible? def myprint(*args, **kw): print(*args, sep="", **kw) If you want, assign print=myprint. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: The "loop and a half"
On 9 October 2017 at 01:37, boB Stepp wrote: > I follow this list in an effort to learn as much as I can even though > I am usually a fish out of water here. But this thread in all its > twists and turns and various subject line changes seems to have gotten > totally out of hand. Even though I am quoting only part of this one > message, there are actually many others that I am responding to here. > > In my opinion (Honestly admitting my lack of technical competence.), > this insatiable thirst on this list to get every bit of technical > minutiae exactly correct is doing a severe disservice to the > friendliness of this community. Yes, gently correct the (perceived) > errors, because we all want to have it right, but please cease this > incessant pounding of points (and people) into the ground to prove we > are right and they are wrong! > > I doubt any of this is going to change Bart's mind. Why can we not > allow him to make his points, respond to them appropriately, and then > let it go when it is clear he has strongly held opinions that are not > likely to change? > > And Bart, when large numbers of technical experts in their fields have > spent many hours/months/years, yea, even several decades, developing > these software systems, why do you think that you, all by yourself, > know better? Can you not see how frustrating this is for people who > have spent good chunks of their lives trying to do the best they can > on these software systems? Don't you think it is a better approach to > perhaps do some self-examination and approach things from a more > humble learner's perspective? And BTW, there are many users of > non-*nix systems on this list, or who do work on multiple operating > system platforms. > > Can we not let people be who they are, perceived warts (valid or not) > and all, and after responding (hopefully gently) to technical errors > just let them be??? +1 Thank you for saying this. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: The "loop and a half"
On 10 October 2017 at 13:44, bartc wrote: >> Can you not see how frustrating this is for people who >> have spent good chunks of their lives trying to do the best they can >> on these software systems? > > Only if they concede I might have a point. I haven't seen much sign of that! You have a point, if you're willing to work in a simplified environment. Like most older, larger systems, a lot of the complexity comes from trying to support a large number of environments/configurations, many more than anyone could have envisioned at the start. Code gets layered on top of older code to support extra situations. Refactoring and simplification is possible, but often really hard because not all of the peculiar situations that prompted the complexity can be reproduced (or even remembered, much of the time) by the developers. Strict "no fix is allowed without a failing test demonstrating the bug" policies can help with that, but in practice such policies are *really* onerous, and tend to risk preventing necessary fixes being applied. The problem is that someone coming in saying "it could be so much simpler" is probably only considering a very small subset of the situations that have come up over the lifetime of the project. Summary: "Things don't need to be this complicated" is likely true. But the cost of simplifying is likely to either be massive coding effort, or reintroduction of obscure bugs that were previously fixed. So I've conceded that you might have a point. Are *you* willing to concede that you may have missed something when making your assertions? Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'
On 10 October 2017 at 15:37, xieyuheng wrote: > 1. 'setattr(o, name, value)' can be used for what kind of objects ? > >section '2. Built-in Functions' >of the official documentation says : > >> The function assigns the value to the attribute, provided the object > allows it. Anything for which o. = value will work. However, user defined types can choose to raise an exception if you try to assign to certain attributes, types with slots will raise an exception if you try to assign to an attribute not defined in __slots__, etc. These are all run-time behaviours, and so there's no way you can check for them ahead of time. If you want to be sure setattr is allowed, you need to handle possible exceptions: try: setattr(o, name, value) except Exception: # deal with the problem Example: >>> class C: ... __slots__ = ['a', 'b'] ... >>> c = C() >>> c.c = 1 Traceback (most recent call last): File "", line 1, in AttributeError: 'C' object has no attribute 'c' >>> setattr(c, 'c', 1) Traceback (most recent call last): File "", line 1, in AttributeError: 'C' object has no attribute 'c' >>> try: ... setattr(c, 'c', 1) ... except AttributeError: ... pass ... >>> > 2. what kind of functions does not have signature, >so that 'inspect.signature(f)' can be used for them ? > >section '29.12.3. Introspecting callables with the Signature object' >of the official documentation says : > >> Some callables may not be introspectable in certain implementations of > Python. >> For example, in CPython, some built-in functions defined in C >> provide no metadata about their arguments. > >this is depends on implementation, so I ask for CPython. Again, it's a runtime issue, so the answer is the same "it's easier to ask for forgiveness than permission" - try the operation and handle any exception: >>> import inspect >>> inspect.signature(type) Traceback (most recent call last): File "", line 1, in File "C:\Users\me\AppData\Local\Programs\Python\Python36\Lib\inspect.py", line 3033, in signature return Signature.from_callable(obj, follow_wrapped=follow_wrapped) File "C:\Users\me\AppData\Local\Programs\Python\Python36\Lib\inspect.py", line 2783, in from_callable follow_wrapper_chains=follow_wrapped) File "C:\Users\me\AppData\Local\Programs\Python\Python36\Lib\inspect.py", line 2262, in _signature_from_callable skip_bound_arg=skip_bound_arg) File "C:\Users\me\AppData\Local\Programs\Python\Python36\Lib\inspect.py", line 2087, in _signature_from_builtin raise ValueError("no signature found for builtin {!r}".format(func)) ValueError: no signature found for builtin >>> try: ... sig = inspect.signature(type) ... except ValueError: ... sig = None ... >>> print(repr(sig)) None Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Python GUI application embedding a web browser - Options?
On 10 October 2017 at 16:07, oliver wrote: > Can you elaborate what is not sufficient with Qt's web components? I can't, sorry. Douglas was resurrecting a thread from a year ago. At the time I was trying to do a quick proof of concept project and asked for help on here. The project never really went anywhere, because it ended up being more complex than I had time for. I don't recall the details any more. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to run pip in Windows 10
On 10 October 2017 at 21:37, Michael Cuddehe wrote: > I have tried multiple versions, 32 & 64 bit. Same problem. > > "This app can't run on your PC. To find a version for your PC, check with > the software publisher." It's difficult to know what to say - it runs fine for me (Windows 10, Python 3.6, 64-bit, downloaded from python.org). Maybe check that the file you downloaded is complete, by confirming the size/checksum matches? Do you have any antivirus software that could be interfering? Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'
Agreed. I was being lazy and didn't check precisely which exception was raised before writing the code. "Making this code production ready is left as an exercise for the reader" :-) On 11 October 2017 at 01:59, Steve D'Aprano wrote: > On Wed, 11 Oct 2017 02:15 am, Paul Moore wrote: > >> These are all run-time behaviours, and so there's no way you can check >> for them ahead of time. If you want to be sure setattr is allowed, you >> need to handle possible exceptions: >> >> try: >> setattr(o, name, value) >> except Exception: >> # deal with the problem > > > I would say that you should only catch AttributeError here. Anything else is, > in my opinion, a bug in the object o that needs to be spotted and fixed. > > Even catching AttributeError is a bit... suspicious. Why exactly are we trying > to attach attributes to arbitrary objects like None or "Hello World"? > > But certainly if you get something like UnicodeDecodeError or ImportError from > trying to set an attribute, that's a bug in o.__setattr__ that needs fixing. > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to run pip in Windows 10
On 11 October 2017 at 15:46, Michael Cuddehe wrote: > - What exactly did you install? >>> Latest install: Python 3.5.4 (v3.5.4:3f56838, Aug 8 2017, 02:17:05) [MSC > v.1900 64 bit (AMD64)] on win32 >>> Downloaded from python.org. > - Can you start the Python interpreter? >>> Yes...works fine. >* How exactly did you go about this >>> ?? > - How exactly do you try to run pip? >>> Command prompt: c:\Users\FFC>pip import (module) >>> > - What exactly happens when you try? >>> Windows error message: "This app can't run on your PC" There's no "pip import" command - I guess you meant "pip install"? Rather than transcribing what you did, can you include a copy and paste of the actual text in your command window? I also googled for the message you quoted, and I see that it's a Windows message (not one from pip or Python). The most obvious suggestion from that was "you're running a 64-bit application on a 32-bit Windows". I note from the above: > Latest install: Python 3.5.4 (v3.5.4:3f56838, Aug 8 2017, 02:17:05) [MSC > v.1900 64 bit (AMD64)] Are you running 32-bit Windows? If so, you got the wrong version of Python (you need the 32-bit version). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to run pip in Windows 10
"Access is denied" sounds like you've installed Python for all users (i.e. in C:\Program Files) and you're not using an elevated prompt to run pip. If you have Python in C:\Program Files, you either need to install modules in your user environment (via pip install --user) which means they'll only be visible to you, or you need to be running as a system administrator to install them for anyone (which means running pip from a command prompt that was opened via "run as administrator") Paul On 11 October 2017 at 16:43, Michael Cuddehe wrote: > Running 64 bit Windows 10. > Re-installed Python 3.6.3 - Download Windows x86-64 web-based installer. Same > problem. > Screen capture attached. > > > -Original Message- > From: Paul Moore [mailto:p.f.mo...@gmail.com] > Sent: Wednesday, October 11, 2017 10:10 AM > To: Michael Cuddehe > Cc: Thomas Jollans; python-list@python.org > Subject: Re: Unable to run pip in Windows 10 > > On 11 October 2017 at 15:46, Michael Cuddehe wrote: >> - What exactly did you install? >>>> Latest install: Python 3.5.4 (v3.5.4:3f56838, Aug 8 2017, 02:17:05) >>>> [MSC >> v.1900 64 bit (AMD64)] on win32 >>>> Downloaded from python.org. >> - Can you start the Python interpreter? >>>> Yes...works fine. >>* How exactly did you go about this >>>> ?? >> - How exactly do you try to run pip? >>>> Command prompt: c:\Users\FFC>pip import (module) >>>> >> - What exactly happens when you try? >>>> Windows error message: "This app can't run on your PC" > > There's no "pip import" command - I guess you meant "pip install"? > > Rather than transcribing what you did, can you include a copy and paste of > the actual text in your command window? > > I also googled for the message you quoted, and I see that it's a Windows > message (not one from pip or Python). The most obvious suggestion from that > was "you're running a 64-bit application on a 32-bit Windows". I note from > the above: > >> Latest install: Python 3.5.4 (v3.5.4:3f56838, Aug 8 2017, 02:17:05) >> [MSC >> v.1900 64 bit (AMD64)] > > Are you running 32-bit Windows? If so, you got the wrong version of Python > (you need the 32-bit version). > Paul > > > --- > This email has been checked for viruses by AVG. > http://www.avg.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Return str to a callback raise a segfault if used in string formating
As a specific suggestion, I assume the name of the created file is a string object constructed in the C extension code, somehow. The fact that you're getting the segfault with some uses of that string (specifically, passing it to %-formatting) suggests that there's a bug in the C code that constructs that string. That's where I'd start by looking. Maybe something isn't zero-terminated that should be? Maybe your code doesn't set up the character encoding information correctly? Paul On 13 October 2017 at 11:15, Thomas Jollans wrote: > On 2017-10-13 11:07, Vincent Vande Vyvre wrote: >> Le 13/10/17 à 09:23, Chris Angelico a écrit : >>> On Fri, Oct 13, 2017 at 4:46 PM, Vincent Vande Vyvre >>> wrote: Simplified code: ---%<-- ... ---%<-- If I place self.callback() at the end of the func process that doesn't change anything. >>> First off, exactly what version of Python are you running this under? >>> With a segfault, you need to be pretty specific - platform, version, >>> word size, as much as you can gather. >>> >>> Secondly: Can you create a version of this that doesn't comment out >>> part of the work? If you can make a script where, any time you run it, >>> Python segfaults, that would be extremely helpful. >>> >>> Your code currently looks a bit weird. You create a thread, start it, >>> and then immediately wait for it (join()). When you add a task, if >>> it's the first task you've added, you process tasks, thus removing >>> that task. So the class isn't actually doing anything, and logically, >>> you could simply process the files directly in the loop. I'm guessing >>> that something in there (probably the threading) is causing the crash, >>> but without a complete and testable demo, it's hard to be sure. >>> >>> ChrisA >> >> I'm using 3.6.1 in venv >> >> It's not easy to write a runnable code because in this example the >> method process() is too simplified and the code don't reproduce the >> segfault. > > That is what you'll have to do, though. > If you strip out as much as possible to create a minimal, working, > complete example, you will have a much easier time reasoning about what > is happening. This will also allow other people to reproduce the > problem, and help. > >> The code is an image processing in two parts: the processing himself in >> CPython and an api in Python. > > If you have custom C code, it's likely that there is a memory management > problem there. It's not unusual for incorrect memory management to cause > problems in a completely different part of the code, where something > tries to access freed memory or something. > > If removing a call to C fixes it, I recommend you carefully check the > memory management logic of your C function. > > >> >> I have written the two parts. >> >> In the real code this is the equivalent of the method process(): >> -- >> def unraw(self, index=0, dest=""): >> """Run the demosaication process. >> >> Args: >> index -- the index of the image or "all" if there's more than >> one image >> into the file >> dest -- the absolute file name for the image decoded. If a file >> with >> the same name already exists, it will be overwritten. >> >> Raise IndexError if index >= self.image_count >> """ >> if not self.is_raw: >> fname = os.path.basename(self.filename) >> raise TypeError("RAW file %s not supported!" % fname) >> >> if index >= self.data["image_count"]: >> raise IndexError("Index of image %s out of range(%s)" >> %(index, self.data["image_count"])) >> >> multi = 0 >> if index == "all": >> multi = 1 >> index = 0 >> >> if not dest: >> dest = self.filename >> >> target = os.path.splitext(dest)[0] >> res = self.raw.demosaicate(index, multi, target)# This call >> the CPython code >> self.out_filename = self.raw.out_file >> >> def run_multitasks(self): >> def process(*args): >> fname, idx, oname = args >> self.identify() >> self.unraw(idx, oname) >> >> while self.tasks: >> t = Thread(target=process, args=self.tasks.pop(0)) >> t.start() >> t.join() >> if self.callback: >> self.callback(self.out_filename) >> >> >> I use a list of 20 files and all files are converted, one by one, >> because the CPython part is not thread safe. >> >> But the real interesting thing is the behaviour in the slot() function. >> >> Examples: >> 1 --- >> def slot(name): >> if os.path.isfile(name): >> print("Created:", name, type(name)) >> prin
Re: Return str to a callback raise a segfault if used in string formating
On 13 October 2017 at 12:18, Vincent Vande Vyvre wrote: > Le 13/10/17 à 12:39, Paul Moore a écrit : >> >> As a specific suggestion, I assume the name of the created file is a >> string object constructed in the C extension code, somehow. The fact >> that you're getting the segfault with some uses of that string >> (specifically, passing it to %-formatting) suggests that there's a bug >> in the C code that constructs that string. That's where I'd start by >> looking. Maybe something isn't zero-terminated that should be? Maybe >> your code doesn't set up the character encoding information correctly? >> >> Paul > > That was my first idea, because I can verify the instance of PyUnraw is not > destroyed when I use the file name, but I was in trouble by the usage of the > file name in string formatting. > > For example I can use the file name into the slot i.e. shutil.copy(fname, > "path/renamed.tiff") > The file is correctly copied. > > In fact, I can do anything with the file name except use it in string > formatting, then your approach is probably a good way. > > Into the CPython part I have a c-string pythonized by: > temp = self->outfname; > self->outfname = PyUnicode_FromString(ofname); > Py_XDECREF(temp); > > and exposed to Python with: > static PyMemberDef PyUnraw_members[] = { > {"out_file", T_OBJECT_EX, offsetof(PyUnraw, outfname), 0, > "Path of the decoded file"}, OK. I presume ofname is UTF-8 encoded as required by PyUnicode_FromString, and you're not accidentally getting a different encoding? I don't see any obvious issue - but it's still far more likely it's an issue in the C code somewhere. Maybe a refcounting bug - those often trigger peculiar errors as memory gets freed too soon, and something then references freed memory. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Lies in education [was Re: The "loop and a half"]
On 13 October 2017 at 13:54, Gregory Ewing wrote: > Neil Cerutti wrote: >> >> I can tell at a glance if a parameter is expected to be >> modifiable just by looking at the function signature. > > > The question is why doesn't anyone feel the need to be > able to do that for Python functions? Whether a function > modifies things passed to it is just as important to > know in Python as it is in C. While I don't *really* know, my intuition is that const is important in C for guaranteeing that functions don't mess around with the innards of (conceptually) primitive types. Hence const char *, and const pointers/arrays. More complex types like collections - lists, trees, etc - can't be declared as "const". Well, they can, but typically that doesn't guarantee that the collection isn't changed, just that the pointer to it isn't. So in C, for all practical purposes const signifies that an argument is what in languages like C# would be called a value type - an immutable primitive value. In Python and other higher level languages, primitive types are immutable by default, or to put it another way, basic types are always value types, and constness is part of the definition of the *type* rather than of the name referring to it. So there's no need for an explicit "const" annotation. To put it another way, in C const is a property of the variable being declared, not the value assigned to it. In Python, variables aren't declared, and constness is an inherent property of the value (or its type). One interesting question which this does raise is whether there's a place for "const" in type annotations - I suspect not, because it's either trivial (the type is immutable) or too hard to define (you'd need to recursively know for all methods whether they mutate the value). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Return str to a callback raise a segfault if used in string formating
On 14 October 2017 at 16:06, Vincent Vande Vyvre wrote: > I think I've found the problem, the string (a file path) is modified in c > with "sprintf, snprintf, ..." And I plan to change that with some CPython > equivalent function. Nice :-) Glad you found it. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: how to read in the newsreader
On 16 October 2017 at 15:41, Grant Edwards wrote: > On 2017-10-16, Terry Reedy wrote: >> On 10/15/2017 10:50 PM, Andrew Z wrote: >>> Gents, >>> how do i get this group in a newsreader? >> >> Point your newsreader to news.gmane.org, > > That, IMO, is the only sane way to read mailing lists. If a mailing > list isn't carried on gmane, I don't bother with it. Unless you work regularly on multiple PCs, as there's no newsreader I know of that maintains your settings (what articles you have read, in particular) across multiple installations. And gmane's UI sucks. For that situation, reading mailing lists as mails in gmail is the best option I've been able to find (not ideal, but adequate). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: how to read in the newsreader
On 16 October 2017 at 16:07, Grant Edwards wrote: > On 2017-10-16, Paul Moore wrote: >> Unless you work regularly on multiple PCs, as there's no newsreader I >> know of that maintains your settings (what articles you have read, in >> particular) across multiple installations. > > Ah yes. I solved problem that by writing a wrapper around slrn so > that my .newsrc and .score files reside "in the could". [They're > actually just sitting in my home directory on a Unix server which I > can scp them to/from. Something like that would be great, but not practical for me to write myself. I'm on Windows machines, and Windows newsreaders from what I recall aren't as hackable as Unix ones (I'm able to write the code, but not if the data isn't accessible...). Also, on at least one of my PCs I'm behind a firewall that blocks access to pretty much all "personal cloud storage" sites, so a DIY solution isn't possible. Something like Chrome's "sync my settings" would be ideal, but I've never found anything like that in a newsreader. > You mean the gmail web UI? I don't even use that e-mail (and I use > gmail for all my e-mail). Yep. Same reason, it's the only globally accessible option. (I could use a mail client on the systems that don't block IMAP, but I'd still need the web UI for the others, and for "borrowed" PCs that I have no software on). The cloud is great, but the app UIs are still a lot worse than a dedicated client app, sadly... Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Application and package of the same name
On 19 October 2017 at 19:18, Skip Montanaro wrote: > I'm not understanding something fundamental about absolute/relative > imports. Suppose I have an application, fribble.py, and it has a > corresponding package full of goodies it relies on, also named fribble. > From the fribble package, the application wants to import the sandwich > function from the lunchtime module. At the top level it thus has an import > like this: > > from fribble.lunchtime import sandwich > > I might have a directory structure like this: > > example > example/fribble.py > fribble > __init__.py > lunchtime.py > > If I run inside the example directory with PYTHONPATH=.. I can't > find/import the fribble package, because the main application directory is > prepended to sys.path. Consequently, the import machinery never gets any > further down sys.path. It stumbles on the fribble application and tries to > find the bits it's interested in, to no avail. > > This is in Python 2.7, FWIW. What am I missing? My immediate reaction is "you shouldn't name your main program and your package the same". It's not a pattern I've seen commonly used. However, the approaches I've seen used (a __main__.py inside the package, so you can execute it via `python -m fribble`, or a setup.py entry point to generate a script wrapper for the application) may be more common among people focused more on library development than on application development. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On 23 October 2017 at 10:32, wrote: > According to this website. This is an uncompressable stream. > > https://en.m.wikipedia.org/wiki/Incompressible_string > > 12344321 > > It only takes seven 8 bit bytes to represent this Would you care to provide the seven 8-bit bytes you propose to use? Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On 23 October 2017 at 15:29, wrote: > I'm really not trolling, and even though some are sarcastic i sm learning > from your comments. I'm willing to believe that, but if you're trying to claim you have "compressed" data (in a way that satisfies the technical, information-theoretic meaning of the word), you need to be *really* careful not to include hidden information in your assumptions. For example, if I have a string made up of only the numbers 0-7, then I can trivially (octal) store that data in 3 bits per digit. But that's not compression, as there's "hidden information" in the knowledge that you're using a restricted character set. Factor in that information and your string only contains 3 bits of information per digit. Using bytes (characters, if you assume a 1-byte encoding) to hold just the digits 0-9 is inefficient (there's 256 bytes and you're only using 10 of them), and "of course" you can hold that data more efficiently. But that's not "compression", that's simply using a better encoding. In the technical sense, "compression" is about looking at redundancies that go beyond the case of how effectively you pack data into the bytes available. > Dec to bin is not bad at removing wasted space Yep, you're not talking about what people usually refer to as compression, but rather about optimising an encoding. >, but there is a better way. Here is an example. How would you compress these >numbers. 10 digits = log2(10) bits of information. So getting down to 4 bits is about encoding. You can go further by using a variable length encoding and "extra knowledge" about which digits come up most commonly to give the common digits shorter representation. That's called Gray coding. You can use the fact that repeated copies of the same digit come up together a lot to replace them by digit + count. That's run-length encoding. There are other more complex approaches. But what *all* of these have in common is that if you provide random input (within the limits of what you support - digit strings here) then you'll *always* get at least one input that encodes to a longer output than your input. > Compress this: > > 4135124325 10 x 10 digits = 10 x log2(10) bits of information = a bit under 34 bits of information > > Bin to dec...still very large > 0110 > 0000 > 1101 > 01100101 4x8 = 32 bits, but there's probably a couple of leading zeros needed if you want to encode all 10-digit numbers. > New compression method: > > 11000101 > 11000111 > 0100 > > A full byte less than bin. You'll need to explain how to decode this, in a way that can be used to decode the encodings of arbitrary 10-digit numbers, and with any leading zeroes that are needed to cover the whole space of 10-digit numbers, before you can claim you've compressed 10-digit numbers using only 24 bits. And if you do that, you've basically overturned most of information theory, so I'd start by assuming there's a flaw in your argument - sorry about that... ;-) Hope this helps put the subject into context. Compression is a very technical subject, to "do it right". Special cases can be worked out, sure, but the "hidden assumptions" in a method are what make the difference between a "compression algorithm" and a "way of storing my particular data more efficiently". > I know many are skepticalthats okay.this has taken 6 years, im not going > to insult your intelligence with something so juvenile as dec to bin. I'm > really trying to find an application for this since it only deals with digits > 0-9 or 0-20 or other strange combinations. Wait did you just give it away in > that small exampleno, because it also encrypts in a way that has never > been done. The compression is better than log(256)÷log (10)wait isn't > that impossible, binary is minimalistic. I agree that binary is minimalistic, > but the architecture is not, making all arguments conjecture...not laws. No-one is going to accept a claim that an algorithm you're not willing to publish is valid. This is about maths/science, not "proprietary algorithms" or anything like that. If you don't publish your methods, people will simply point at information theoretic proofs and say "either you're missing something, or your approach doesn't work in cases that I care about, so thanks but no thanks". Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On 24 October 2017 at 09:43, Gregory Ewing wrote: > Paul Moore wrote: >> >> But that's not "compression", that's simply using a better encoding. >> In the technical sense, "compression" is about looking at redundancies >> that go beyond the case of how effectively you pack data into the >> bytes available. > > > There may be a difference in the way the terms are used, but > I don't think there's any fundamental difference. Compression > is about finding clever ways to make the encoding better. Agreed - I was trying (probably futilely, given the way this thread has gone...) to make a distinction between purely local properties that are typically considered in "how you encode the data" and the detection of more global patterns, which is where what are typically referred to as "compression" algorithms get their power. But sadly, I don't think the OP is actually interested in understanding the background, so the distinction wasn't really worth making :-( > Either way, the information-theoretic limits on the number > of bits needed are the same. Precisely. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On 24 October 2017 at 11:23, Ben Bacarisse wrote: > For example, run the complete works of Shakespeare through your program. > The result is very much not random data, but that's the sort of data > people want to compress. If you can compress the output of your > compressor you have made a good start. Of course what you really want > to be able to do is to compress the output that results from compressing > your compressed out. And, of course, you should not stop there. Since > you can compress *any* data (not just the boring random stuff) you can > keep going -- compressing the compressed output again and again until > you end up with a zero-length file. Oh, and just for fun, if you are able to guarantee compressing arbitrary data, then 1. Take a document you want to compress. 2. Compress it using your magic algorithm. The result is smaller. 3. Compress the compressed data. The result is still smaller. 4. Repeat until you hit 0 bytes. Congratulations - apparently you have a reversible algorithm that compresses every data set to an empty file. (Caveat - there's actually "hidden data" here, as you need to know how many compressions it takes to hit 0 bytes. Because you decrease the size every time, though, that number must be no greater than the size of the original file). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On 24 October 2017 at 12:04, Ben Bacarisse wrote: > Paul Moore writes: > >> On 24 October 2017 at 11:23, Ben Bacarisse wrote: >>> For example, run the complete works of Shakespeare through your program. >>> The result is very much not random data, but that's the sort of data >>> people want to compress. If you can compress the output of your >>> compressor you have made a good start. Of course what you really want >>> to be able to do is to compress the output that results from compressing >>> your compressed out. And, of course, you should not stop there. Since >>> you can compress *any* data (not just the boring random stuff) you can >>> keep going -- compressing the compressed output again and again until >>> you end up with a zero-length file. >> >> Oh, and just for fun, if you are able to guarantee compressing >> arbitrary data, then > > It's a small point, but you are replying to a post of mine and saying > "you". That could make people think that /I/ am claiming to have a perfect > compression algorithm. Sorry. I intended the meaning "If one is able to..." but I was unclear. My bad. >> 1. Take a document you want to compress. >> 2. Compress it using your magic algorithm. The result is smaller. >> 3. Compress the compressed data. The result is still smaller. >> 4. Repeat until you hit 0 bytes. > > Isn't this just repeating what I said? I must has not written is > clearly enough. More accurately, I didn't read it carefully enough. Again sorry. However, I guess it serves as an example of a compression algorithm - we can trivially compress the content of our two posts into a single post with just as much information content, by deleting my post :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: install on host not connected to the internet and no local proxy
On 2 November 2017 at 07:17, Chris Angelico wrote: > On Thu, Nov 2, 2017 at 5:50 PM, Noah wrote: >> Hi, >> >> I am trying to install a python package with about 80 dependencies on a >> server that is not connected to the internet and has no local proxy. I can >> ssh to it via VPN. >> >> I was able to find python bundle and download the tarballs for all the main >> python package and all the tarballs for the subsequent dependencies.They >> reside in the same directory on the isolated server. >> >> Does anybody have some recommendations on how to install the main package >> and that process triggers the installation of all the dependencies from >> their corresponding tar.gz file? I cant seem to figure out how to do that >> easily with pip. > > Hmm. The first thing that comes to my mind is a virtual environment. > I'm assuming here that you have a local system that has the same CPU > architecture and Python as the main server, and which *does* have an > internet connection; if that's not the case, it'll be more > complicated. But in theory, this should work: > > local$ python3 -m venv env > local$ source env/bin/activate > local$ pip install -r requirements.txt > > At this point, you have a directory called "env" which contains all > the packages listed in your requirements.txt file (you DO have one of > those, right?) and everything those packages depend on. Then SSH to > your server, and set up an equivalent environment: > > server$ python3 -m venv env > server$ source env/bin/activate > > Copy in the contents of env/lib/pythonX.Y/site-packages (where X.Y is > your Python version, eg python3.7 on my system), and then try > importing stuff. In theory, you should be able to load everything in > just fine. > > If that doesn't work, you might have to manually run setup.py for each > of your eighty dependencies, and possibly all of their dependencies > too. I'd definitely try the venv transfer before going to that level > of tedium. Alternatively, you can do (on your internet-connected system) mkdir wheels pip wheel --wheel-directory wheels -r requirements.txt This will create a set of .whl files in the directory "wheels". You can copy that directory to the target machine and (assuming the two machines do have the same architecture/OS) on that machine do pip install --no-index --find-links wheels -r requirements.txt This will tell pip to not use PyPI (and so not need the internet) and to satisfy the requirements using only the wheel files in the "wheels" directory. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: [TSBOAPOOOWTDI]using names from modules
On 5 November 2017 at 01:19, Steve D'Aprano wrote: > On Sun, 5 Nov 2017 06:42 am, Stefan Ram wrote: > >> What is the one way to do it? > > There is no philosophy of "one way to do it" in Python, that is a > misunderstanding (possibly deliberate...) spread about by Perl users, to > contrast Python from Perl's "more than one way to do it". > > The Zen of Python says: > > There should be one-- and preferably only one --obvious way to do it. > > > The emphasis is on "obvious", not "one". There should be *at least* one, but > preferably only one, OBVIOUS way to solve any problem. > > As for the question of importing names, the obvious way is to use a regular > import: > > > import math > y = math.cos(x) > > > which has the advantage of making it obvious where the name comes from, but > the disadvantage that it is more to type and involves an extra name lookup at > runtime, which is not free. > > But: > > - when performance matters > > - or the name is very well known > > - or you're only using a single name from the module (or at most a few) > > - especially if it repeats the module name (e.g. fractions.Fraction) > > it is acceptable to use the "from module import name" version: > > from math import cos > y = cos(x) > > > Which you use depends on the situation and personal taste. Also, if what you are trying to "do" is different (for example, you're trying to write code that looks familiar to mathematicians) the obvious way may be different too (so "from math import cos" may be the obvious approach in that situation). But regardless, the Zen isn't intended to be taken quite as literally as the OP was trying to do. It's a statement of principles, not a set of rules. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Read Firefox sqlite files with Python
On 5 November 2017 at 01:22, Steve D'Aprano wrote: > On Sun, 5 Nov 2017 04:32 am, Steve D'Aprano wrote: > >> I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. >> >> >> import sqlite3 >> con = sqlite3.connect('foo.sqlite') >> with open('dump.sql', 'w') as f: >> for line in con.iterdump(): >> f.write(line + '\n') > > > Never mind. I dumped the file using the sqlite3 command line tool. Thank you > to all those who answered. > > The file contains three INSERT statements, the first two don't have anything > of interest, and the third (which presumably contains all the data I'm trying > to recover) is an opaque 600+ KB blob. > > Naturally. Why would you use a database as a database, when instead you could > just dump a big ball of mud into it? Hmm, *.sql files normally contain SQL source code (as this one does). SQLIte databases in my experiences typically use either ".sqlite" or ".db" for the extension. Are you sure you're looking at the right file? Alternatively I guess it's possible that Firefox creates an in-memory database, then executes the dump.sql file to populate it, for performance reasons. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: [TSBOAPOOOWTDI]using names from modules
On 5 November 2017 at 13:54, Stefan Ram wrote: > Paul Moore writes: >>But regardless, the Zen isn't intended to be taken quite as literally >>as the OP was trying to do. It's a statement of principles, not a set >>of rules. > > What I am looking for is a default notation to use in my > beginner's tutorial and also to recommand for beginners. Then "import math" at the top of the file, and refer to module functions as "math.sin". That's the normal approach you'd see in pretty much every Python project on the web, so "follow normal practice" applies. By the time your students know enough to ask if there's a way to avoid needing to repeat "math" (and understand the answer) they are likely to be experienced enough to judge which option is better in a given situation. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Easiest way to access C module in Python
On 7 November 2017 at 11:16, Chris Angelico wrote: > Thanks for the FUD. I love it when someone, on the basis of one failed > experiment, trash-talks an excellent piece of software that would > solve the OP's problem. It *is* true that the learning curve for Cython is steeper than that of ctypes. But for anything more complex than simple "call a function with no arguments", ctypes rapidly gets fairly complex and messy - and the docs are not exactly the best. At that point, investing the time in learning how to use Cython definitely pays off. Another option for the OP is cffi, which might offer a middle ground (in terms of complexity vs power - it's hard to objectively assess "complexity" without knowing the audience's background). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: What happens to module's variables after a "from module import" ?
On 7 November 2017 at 15:39, ast wrote: > Hello > > Here is my module tmp.py: > > a=0 > > def test(): >global a >print(a) >a+=1 > > If I import function "test" from module "tmp" with: > from tmp import test > > > it works > test() > > 0 test() > > 1 > > But where variable "a" is located ? I can't find it anywhere It's in the "tmp" module, where you defined it. But because you didn't ask for a reference to it in your import statement, it's not accessible to you[1]. Do import tmp print(tmp.a) and you can see it. Paul [1] Technically you can find it via the globals of the function test, as test.__globals__['a'], but if you understand how that works, you wouldn't have been asking the question in the first place :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: Any good explanations on pd.merge(df,df2, on=['Code', 'Region'])
On 8 November 2017 at 11:15, Karsten Hilbert wrote: > On Wed, Nov 08, 2017 at 09:26:04AM +, David Shi via Python-list wrote: > >> I am trying to gain a clear understanding on pd.merge(df,df2, on=['Code', >> 'Region']). >> Can anyone assist? > > ncq@hermes:~$ python > Python 2.7.14 (default, Sep 17 2017, 18:50:44) > [GCC 7.2.0] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> pd.merge(df,df2, on=['Code', 'Region']) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'pd' is not defined > >>> > > You will need to provide more context to get help. ... but given that I happen to know (mostly by chance) that pd is a commonly used short form when importing Pandas ("import pandas as pd") you should probably start with the documentation on merge: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html If that isn't sufficient for you, please provide a better explanation of what you don't understand, what you have tried and how it didn't match your expectations, and maybe someone on the list who is familiar with Pandas will be able to assist you. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Ideas about how software should behave
On 9 November 2017 at 05:08, Ben Finney wrote: > Marko Rauhamaa writes: > >> Jon Ribbens : >> > It is my experience of this group/list that if one disagrees with any >> > of you, Steve and Chris, you all rally round and gang up on that >> > person to insult and belittle them. This makes the atmosphere quite >> > hostile, and it would be quite remarkable if it isn't hurting the >> > community by driving people away. Please stop doing it. >> >> This forum is about a dead thing, a programming language. I wouldn't >> make too big a deal about "the community." > > On the contrary, this forum is about a *community of people*, formed > around a programming language. > > The community is primary here, I am in full agreement with Jon on that. 100% agreed. And on that note, shouldn't participants on this list follow the Python code of conduct[1]? Specifically, I don't see a lot of adherence to the mandate to be "tactful when approaching differing views" in this debate :-( Tact isn't about explaining how what *you* said shouldn't be taken the way the other person appears to be taking it. It's about accepting that the other person took your words in a particular way, and acknowledging and dealing with the fact that their interpretation is real to them, and should not be dismissed as "mistaken". Paul [1] https://www.python.org/psf/codeofconduct/ PS I won't respond to any explanations of how what I'm saying here is incorrect, or misguided. I don't want to further fan the flames. -- https://mail.python.org/mailman/listinfo/python-list
Re: can't get python to run
On 12 November 2017 at 19:58, Mary Ann via Python-list wrote: > > trying to install and run Python 3.5.2 (64 bit) and keep getting error > message: > > the program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing > from your computer. Try reintalling the program to fix this problem. > > I am on Windows 7 Home Premium > > I have uninstalled and reinstalled 3.5.2 several times and tried repairing > and still the error message keeps coming back and i can't run python 3.5.2 > > I was able to run Python27 and it opened just fine. > > > I am not a computer person and am just starting to learn python and the > professor said to install 3.5.2. I just have no idea what the issue is other > than maybe an old computer This is something that comes up for people quite often. In a situation like this, you can often find useful advice by searching Google. I put the message "api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer" into Google, and got a few hits immediately that would probably have been helpful to you. What you should do is to download and install the "Visual C++ redistributable for Visual Studio 2015", which you can get from https://www.microsoft.com/en-in/download/details.aspx?id=48145 You may also find that if you run "Check for updates" on your PC, this will be installed automatically - MS do distribute this update automatically, and it may be that you simply haven't updated recently. But the manual install will work just as well. Hope this helps, Paul PS The reason Python 2.7 works, is that it uses an older version of Visual C, which doesn't need the newer runtime installed. -- https://mail.python.org/mailman/listinfo/python-list
Re: "help( pi )"
On 17 November 2017 at 12:36, Stefan Ram wrote: > A web page says: > > “The argument to pydoc can be the name of a function, > module, or package, or a dotted reference to a class, > method, or function within a module or module in a package.” [...] > , but not for »pi«: > > from math import pi > help( pi ) math.pi is not "a class method, or function within a module or module in a package". It's a number. I can see why you would want to be able to do this, but technically the help function shows the object's docstring, and numbers don't have docstrings. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: "help( pi )"
On 17 November 2017 at 15:52, Marko Rauhamaa wrote: > Paul Moore : >> numbers don't have docstrings. > > There's no reason they couldn't: In the sense that the Python object model could be amended to attach docstrings to instances of classes like "int", and syntax could be added to the language to write those docstrings in your code, then yes, of course there's no reason they couldn't. I'd say "patches gratefully accepted" but actually I suspect "justifications for why the extra complexity is worth it, followed up with a patch, might just be accepted if the justification were *extremely* strong" is more accurate ;-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: reading text in pdf, some working sample code
I haven't tried it, but a quick Google search found PyPDF2 - https://stackoverflow.com/questions/34837707/extracting-text-from-a-pdf-file-using-python You don't give much detail about what you tried and how it failed, so if the above doesn't work for you, I'd suggest providing more detail as to what your problem is. Paul On 21 November 2017 at 15:18, Daniel Gross wrote: > Hi, > > I am new to python and jumped right into trying to read out (english) text > from PDF files. > > I tried various libraries (including slate) out there but am running into > diverse problems, such as with encoding or buffer too small errors -- deep > inside some decompression code. > > Essentially, i want to extract all text and then do some natural language > processing on the text. Is there some sample code available that works > together with a clear description of the expected python installatin > environment needed. > > In slate btw, i got the buffer error, it seems i must "guess" the right > encoding of the text included in the PDF when opening the file. Still > trying to figure out how to get the encoding info out of the PDF ... (if > available there) > > thank you, > > Daniel > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)
On 27 November 2017 at 18:13, Skip Montanaro wrote: >> If you have a Windows key, you can assign it to be >> the Compose key. > > Would this be true on a machine running Windows? My work environment > has me developing on Linux, with a Windows desktop. It's not clear to > me that any sort of xmodmap shennanigans would work. Won't Windows > itself always gobble up that key? Programs can access the Windows key. IIRC, there is a utility that provides compose-key functionality on Windows. I can't recall the name right now and it's on my other PC, not this one, but I'll try to remember to post the name tomorrow... Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Pros and cons of Python sources?
On 27 November 2017 at 20:20, Martin Schöön wrote: > Den 2017-11-26 skrev Cameron Simpson : >> On 26Nov2017 10:00, nospam.Martin Schöön wrote: >>> >>>Hmm, I seem to remember not being able to install packages with pip unless I >>>did sudo pip. >> >> And this is exactly what I'm warning about. Many Linux users see some kind of >> failure and just stick sudo on the front of the command. It is almost always >> the wrong things to do, leading to effects in the OS install area instead of >> being safely contained within one's home directory or work area. >> >> Instead of reaching straight for sudo, look at pip's manual or help. You will >> find that: >> >> pip install --user ... >> >> installs modules local to your home directory, avoiding troublesome installs >> into the OS area. >> > Guilty as charged. > > So, how do I restore order in my Python 2.7 installation? Uninstall > everything that looks, smells and tastes like Python 2.7 and then > re-install? Or just accept that everything's probably fine, but be prepared to deal with the fact that something like that is what you should do if you find a problem you can't resolve yourself and need to ask for help from upstream (e.g., your distro provider or the pip maintainers). It's not so much that anyone's forcing you to do anything a particular way - just setting the boundaries on what they are willing to support if you need help. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers)
On 27 November 2017 at 19:05, Paul Moore wrote: > On 27 November 2017 at 18:13, Skip Montanaro wrote: >>> If you have a Windows key, you can assign it to be >>> the Compose key. >> >> Would this be true on a machine running Windows? My work environment >> has me developing on Linux, with a Windows desktop. It's not clear to >> me that any sort of xmodmap shennanigans would work. Won't Windows >> itself always gobble up that key? > > Programs can access the Windows key. IIRC, there is a utility that > provides compose-key functionality on Windows. I can't recall the name > right now and it's on my other PC, not this one, but I'll try to > remember to post the name tomorrow... WinCompose was the program - https://github.com/samhocevar/wincompose Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] - Re: Has anyone worked on docker with windows
On 30 November 2017 at 18:49, Michael Torrie wrote: > As for running Windows applications in a Windows container, this is not > possible using any container technology I'm aware of. I'm sure MS could > one day build Windows-centric containerization into Windows, but there's > no support now. I guess they haven't figured out how to work out the > licensing. Proprietary licensing and containers would be complex. Way off topic certainly, but I just installed Docker for Windows yesterday, and it has an option on the menu "Switch to Windows containers". From a very quick Google search, it looks like there is support for running Windows-based containers in docker now. There's an image microsoft/windowsservercore available, which suggests this is a supported solution. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get the redirected URL only but not the actual content?
On 2 December 2017 at 03:32, Peng Yu wrote: > Where is `?reload=true` from? How to just get the redict URL that one > would get from the browser? Thanks. > >> 'http://ieeexplore.ieee.org:80/document/771073/?reload=true' The reload=true comes because http://ieeexplore.ieee.org/document/771073/ is itself redirected to that location: >curl -I http://ieeexplore.ieee.org/document/771073/ HTTP/1.1 302 Moved Temporarily Date: Sat, 02 Dec 2017 10:25:58 GMT Location: http://ieeexplore.ieee.org:80/document/771073/?reload=true Set-Cookie: JSESSIONID=YewWwt7dRSRhQWpfvW_L_pCovlFPKnyDULFtYJGxwvaIvmv8-RK-!-1840538570; path=/; HttpOnly;HttpOnly Set-Cookie: ERIGHTS=null; domain=ieeexplore.ieee.org; expires=Thu, 01-Jan-1970 01:00:00 GMT; path=/;HttpOnly Set-Cookie: ipCheck=109.154.64.43; domain=ieeexplore.ieee.org; path=/;HttpOnly Set-Cookie: ipCheck=109.154.64.43; domain=ieeexplore.ieee.org; path=/;HttpOnly Set-Cookie: cookieCheck=true; domain=ieeexplore.ieee.org; path=/;HttpOnly X-XSS-Protection: 1 Set-Cookie: WLSESSION=186802828.20480.; expires=Sun, 03-Dec-2017 10:25:58 GMT; path=/; Httponly Set-Cookie: TS011813a0=012f350623b6ced9dc5148879303ea57ba3f9321e686d26e43e83dddc173810cbaa92efa0046e79b1666b3f14f416143c59004edd9a10f9c23f67089ad348420304ac91dcfd756c69a4bbb7c0afe436aadb111a234; Path=/ Set-Cookie: TS01d430e1=012f3506230b0f867dbbdc2d8cd9812cc6cda6004b86d26e43e83dddc173810cbaa92efa00939a6282cc7ad5b9b80ddea276f6b5409df42e43a52ed561e1234df4ab341c2f3974c06b59548aab1e30a871ec4efc9bba1a756faf9076574ae4a4f67b57fa79856f016141e55bb9497d8dc4bbd4037c; path=/; domain=ieeexplore.ieee.org Transfer-Encoding: chunked Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: why won't slicing lists raise IndexError?
On 4 December 2017 at 20:13, Jason Maldonis wrote: > And I'll be honest -- I like the implementation of the LazyList I wrote > above. I think it's pretty logical, because it allows you to think about > the lazy list like this: "Treat the list like a norma list. If you run out > of bounds, get more data, then treat the list like a normal list again." > And I really like that clean logic. I can't give you a definitive answer as to why slices behave as they do, any more than anyone else (barring probably Guido). But as a user, I can say that I find the ability to use slices without checking for out of bounds cases or handling exceptions to be really convenient. And one thing Python consistently emphasises is making things easy for the user, even if that convenience comes at a cost to the implementer. Certainly, you're a user of the built in list class, but you're using it to build a wrapper around it, and that makes you a non-core use case (as I see it). At the end of the day, whether to clamp the values or raise IndexError is a trade-off in terms of which type of user to inconvenience, and as I say, in my experience user code wins when that sort of trade-off comes up. That's not to say Python makes it deliberately difficult for people writing code like yours. For your lazy list class, do you know the maximum amount of data available? If you don't, then supporting lst[:-1] will be hard, so you're pretty much bound to have to handle slices differently than built in lists. If you *do* know the maximum length of the underlying data, then the indices() method of slices will probably help: Help on built-in function indices: indices(...) method of builtins.slice instance S.indices(len) -> (start, stop, stride) Assuming a sequence of length len, calculate the start and stop indices, and the stride length of the extended slice described by S. Out of bounds indices are clipped in a manner consistent with the handling of normal slices. Using indices(), you'll get (from "stop") the amount of data you need to load. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Stackoverflow question: Is there a built-in identity function in Python?
On 7 December 2017 at 18:28, Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. > > My contention is that an identity function is a do-nothing function that > simply returns what it was given: > > --> identity(1) > 1 > > --> identity('spam') > 'spam' > > --> identity('spam', 'eggs', 7) > ('spam', 'eggs', 7) > > Of the five answers to that SO question, mine is the only one that will > correctly handle those three examples. If you agree with my contention feel > free to up-vote my answer. :) IMO (as a mathematician ;-)) the identity function is a *single-argument* function that returns the value passed to it. So: def identity(x): return x See https://en.wikipedia.org/wiki/Identity_function identity(1,2) is an error. Extending the definition to multiple arguments causes all sorts of confusion, as you've seen. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Stackoverflow question: Is there a built-in identity function in Python?
On 7 December 2017 at 20:35, Chris Angelico wrote: > Because it's impossible to return multiple values. IMO the "identity > function" is defined only in terms of one single argument, so all of > this is meaningless. Indeed, this is the key point. The Python language only allows returning one value (which can be a tuple, sure, but it's still *one value*). So a function that returns what it's called with can only have one argument. Anything else isn't an "identity function". Certainly, it might be useful - "def f(arg, *rest, **kw): return arg" could be a useful dummy function in some contexts, for example - but it's not an identity function in the strict sense (and so you can't avoid having to specify its behaviour explicitly). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem with timeit
On 15 December 2017 at 13:25, ast wrote: > On my computer it takes roughtly 4 s, mesured with a watch. Is your computer particularly old? On my PC, the time it takes to run x=123456**123456 at the Python interpreter prompt is barely noticeable. > I can't do "len(str(x))" to know the size, I have to kill the process Took a few seconds (5-10s) on my PC, and returned 628578. > But x.bit_length() answers 2088091, so x should have about > 60 digits Yep, that's what I get > > If I measure execution time: > t=time(); x=123456**123456; print(time()-t) > > 0.0 Same here. > There is still something wrong As far as I can see, it's in your manual measurement. All of the code you've provided gives the same results on my PC as on yours, but your manual measurements differ drastically from mine (and my manual measurements match what I'd expect given results of timeit/time.time whereas yours don't...). Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWin32 installer question
When I took a quick look at the code, it seemed to be based on a pretty old version of Python. What version are you using? If it's 2.7 (or better still, Python 3!) then you should have pip available. In which case you may be better off using pypiwin32, which is a rebundling of pywin32 as a wheel. "python -m pip install pypiwin21" should work for you. You may need to force the version to be 219, as there's only Python 3.6 wheels for version 220 (do this as "python -m pip install pypiwin32==219") - but I don't think you'll need this, pip should limit itself to compatible wheels. Unfortunately, pywin32 is one of the worst extensions to install, as the project doesn't supply official wheels, and some of the COM stuff needs registration, which in the wininst script is handled by a post-install step, but I've no idea how you do that with a wheel - you may need to ask the project maintainers for advice. Paul On 27 December 2017 at 14:58, Skip Montanaro wrote: > I'm fiddling around with Appveyor, trying to build a Windows installer > for SpamBayes. This is complicated by two facts: > > 1. I don't know squat about Windows. > > 2. I don't have access to a Windows command line. > > Consequently, every new attempt requires a change to appveyor.yml and > a git push command. Rather slow going. My latest Appveyor build number > is 59. Most of the changes were simple fixes for syntax errors. > > I got to the point where I (finally!) was able to successfully > download the appropriate pywin32 installer, but executing it just > hangs. I sort of assume it's asking os.devnull for something. Alas, I > couldn't find any sort of command line flags for the installer itself > in the pywin32 code. I've tried > > pywin32.exe /h > > but that just sits there (ignores that flag?) and > > pywin32.exe /? > > which produced some inscrutable output. > > Is there some way to coax it into giving me some help and exiting? > > Thanks, > > Skip > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWin32 installer question
On 28 December 2017 at 17:49, Skip Montanaro wrote: > pip install py2exe_py2 pypiwin32 Pillow lockfile > Collecting py2exe_py2 > Could not find a version that satisfies the requirement py2exe_py2 > (from versions: ) > > That error message isn't telling me much about why the requirement > isn't satisfied. > > The name of the wheel file suggests that it's architecture-independent: > > py2exe_py2-0.6.9-cp27-none-win32.whl > > Any idea what it's complaining about? That's not an architecture-independent file. The Wheel spec gives all the details, but "cp27" (as opposed to "py27") means it's CPython only (which usually means it's got a C extension) and "win32" is 32-bit only ("win_amd64" is the tag for 64-bit Windows). So the problem is that the py2exe_py2 maintainer doesn't supply a 64-bit build. You could ask the maintainers if they could supply a 64-bit build. You may be able to build your own copy, but without a Windows system, doing so on Appveyor will be a real pain. Another option is to use Christoph Gohlke's builds, from https://www.lfd.uci.edu/~gohlke/pythonlibs/#py2exe - you have to download the wheel file manually (the site doesn't support automated downloads) and then upload it to Appveyor somehow (maybe by keeping a copy of the wheel in the project repo). Also the version there is 0.6.10a1 which looks like an alpha rather than the last official release. So I guess there may be issues with that. Worst case scenario would be to switch to something other than py2exe - cx_Freeze seems similar and pretty good, and it *does* ship 64-bit Python 2.7 wheels. But that's obviously a non-trivial task. Welcome to the bad old days of trying to find Windows binaries for Python packages :-( I'd strongly recommend moving to Python 3, as the situation is immensely improved there - most projects ship Python 3 binary wheels, and "pip install" just works in many cases. But I appreciate that doesn't help much for you. Sorry - hopefully one of the other options above will help. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWin32 installer question
On 29 December 2017 at 16:04, Skip Montanaro wrote: >> Thanks. I'll shoot Thomas Heller an email... > > > Actually, make that Christopher Toth. Seems he's the current maintainer. If you get no joy there, then in a week or two, when I next get access to a system with a Python 2.x build environment on it, I can see if I can do a 64-bit build for you. Ping me if that would be a help. Paul -- https://mail.python.org/mailman/listinfo/python-list