Re: Using Python 2
On Fri, Sep 8, 2017 at 8:42 AM, Marko Rauhamaa wrote: > Chris Angelico : >> But as others have said, upgrading to 3.4+ is not as hard as many >> people fear, and your code generally improves as a result > > That's somewhat irrelevant. Point is, Python 2 will quickly become a > pariah in many corporations during or after 2018, and we are going to > see emergency measures similar to the Y2K craze twenty years ago. > > The risk to Python will be whether the occasion is exploited by fanboys > of competing programming languages. The migration from Python 2 might be > to something else than Python 3 in some circles. A lot of companies I work for say they don't have the time and/or money and/or they don't want to risk breaking things. If python 2 ever is not available I guess then they will have to find the time and money. -- https://mail.python.org/mailman/listinfo/python-list
Python dress
Not too many females here, but anyway: https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress (And if any guys want to wear this, there's nothing wrong with that.) -- https://mail.python.org/mailman/listinfo/python-list
trace not working with rpy2
When I invoke my script with trace it fails with: /usr/local/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:186: RRuntimeWarning: Fatal error: unable to open the base package and the trace file has: __init__.py(1): __init__.py(19): from rpy2.robjects.robject import RObjectMixin, RObject cannot find system Renviron I have tried running trace with both of these options, but I still get the same error. --ignore-module=rpy2 --ignore-dir=/usr/local/lib/python2.7/site-packages/rpy2 Anyone know how I can get around this error so I can use trace? -- https://mail.python.org/mailman/listinfo/python-list
rmtree message
I have a script that creates a tmp dir, create a lot of files in it, and when done, does a rmtree on the dir. When it does that I get this message: shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory But no exception is thrown. How can I determine why I get this message? -- https://mail.python.org/mailman/listinfo/python-list
Re: Old Man Yells At Cloud
On Sun, Sep 17, 2017 at 9:34 AM, wrote: > Experienced Python programmers use the logging module for debugging, write > once, delete (maybe) never. I use pdb for debugging (but I also log a lot which helps with prod system when users report a problem). -- https://mail.python.org/mailman/listinfo/python-list
Re: Old Man Yells At Cloud
On Sun, Sep 17, 2017 at 11:44 AM, Dennis Lee Bieber wrote: > The only pocket calculators I know of that have "integers" are those > with a "programmer's mode" -- ie; binary (displayed in > binary/octal/decimal/hex) but needing to be converted back to "normal" if > one wants to use them with non-binary values. See nearly any of the more > capable HP units. Binary division stays binary (integer). I have a HP-41C that I bought in 1976 for $300. It's sitting on my desk right next to my keyboard. Still use it today. It's awesome. -- https://mail.python.org/mailman/listinfo/python-list
Re: rmtree message
On Wed, Sep 13, 2017 at 5:39 PM, Sean DiZazzo wrote: > On Wednesday, September 13, 2017 at 12:06:20 PM UTC-7, larry@gmail.com > wrote: >> I have a script that creates a tmp dir, create a lot of files in it, >> and when done, does a rmtree on the dir. When it does that I get this >> message: >> >> shell-init: error retrieving current directory: getcwd: cannot access >> parent directories: No such file or directory >> >> But no exception is thrown. How can I determine why I get this message? > > I usually see that message when I am in a directory in the shell but it has > already been deleted by another process. > > Make sure the directory exists. Is another part of your script deleting the > root directory while rmtree is running? Or something of the like. Turned out the script's cwd was in a dir that was being removed. I chdir'ed out of there and that resolved the issue. Thanks to all who responded. -- https://mail.python.org/mailman/listinfo/python-list
Re: Old Man Yells At Cloud
On Mon, Sep 18, 2017 at 11:23 PM, Dan Sommers wrote: > How relevant is the "people use calculators to do arithmetic" argument > today? Okay, so I'm old and cynical, but I know [young] people who > don't (can't?) calculate a gratuity without an app or a web page. I use a calculator all the time - not for calculating a tip though. Sometimes I use bc (when I can't find my calculator in the morass of my desk). True story - the other day I was in a store and my total was $10.12. I pulled out a $20, and the cashier (probably age 23 or so) immediately entered $20 as the amount tendered. Then I said "Let me see if I have the $0.12." I did not, but I had $0.15 so I handed her $20.15. She literally froze in place with a classic deer in the headlights stare. I said "$10.03" She said "What?" I said "$10.03 is my change." She said "What?" I said "Just give me $10." She did not reply, opened the drawer below her register, rummaged around and came out with one of those giant key calculators, and with a look of dogged determination, did the calculation, looked at me and said proudly "$10.03 is your change." -- https://mail.python.org/mailman/listinfo/python-list
Re: Old Man Yells At Cloud
On Tue, Sep 19, 2017 at 10:30 AM, D'Arcy Cain wrote: > On 09/19/2017 06:46 AM, Larry Martell wrote: >> >> True story - the other day I was in a store and my total was $10.12. I > > > One time I was at a cash with three or four items which were taxable. The > cashier rung each one up and hit the total button. She turned to me and > said something like "$23.42 please." She was surprised to see that I was > already standing there with $23.42 in my hand. "How did you do that" she > asked. She must have thought it was a magic trick. I was just in a clothing store this weekend and there was a rack of clothes that was 50%. The sales clerk said everything on that rack was an additional 25% off, so it's 75% off the original price. I asked is it 75% off the original price or 25% off the 50% of the price. Said it's the same thing. I said no it's not. She insisted it was. I said no, let's take a simple example. If it was $100 and it was 75% off it would be $25. But if it's 50% off and then 25% off that it will be $37.50. She looked totally dumbfounded. -- https://mail.python.org/mailman/listinfo/python-list
Re: Even Older Man Yells at Whippersnappers
On Tue, Sep 19, 2017 at 1:38 PM, ROGER GRAYDON CHRISTMAN wrote: > I recall giving a quiz to my college students sometime back around > the late nineties which had a little bit of arithmetic involved in the answer. > It's been too long ago to still have the exact details, but I remember > a couple solutions that would be of the form: > > 5 + 10 + 1*2 > > And then the student would write he was unable to actually > compute that without a calculator. And yes, I deliberately > designed the questions to have such easy numbers to work with. It was my birthday the other day. People at worked asked how old I was. I replied: ((3**2)+math.sqrt(400))*2 Quite a few people somehow came up with 47. And these are technical people. -- https://mail.python.org/mailman/listinfo/python-list
Re: Even Older Man Yells at Whippersnappers
On Tue, Sep 19, 2017 at 2:41 PM, Chris Angelico wrote: > On Wed, Sep 20, 2017 at 4:33 AM, Larry Martell > wrote: >> On Tue, Sep 19, 2017 at 1:38 PM, ROGER GRAYDON CHRISTMAN >> wrote: >>> I recall giving a quiz to my college students sometime back around >>> the late nineties which had a little bit of arithmetic involved in the >>> answer. >>> It's been too long ago to still have the exact details, but I remember >>> a couple solutions that would be of the form: >>> >>> 5 + 10 + 1*2 >>> >>> And then the student would write he was unable to actually >>> compute that without a calculator. And yes, I deliberately >>> designed the questions to have such easy numbers to work with. >> >> It was my birthday the other day. People at worked asked how old I >> was. I replied: >> >> ((3**2)+math.sqrt(400))*2 >> >> Quite a few people somehow came up with 47. And these are technical people. > > *headscratch* Multiple people got 47? I'm struggling to figure that > out. If they interpret the first part as multiplication (3*2 => 6), > that would get 26*2 => 52; if they don't understand the square > rooting, they'd probably just give up; if they ignore the parentheses, > that could give 9 + 20*2 => 49; but I can't come up with 47. They could not explain it either. -- https://mail.python.org/mailman/listinfo/python-list
Re: Even Older Man Yells At Whippersnappers
On Tue, Sep 19, 2017 at 12:12 PM, Rhodri James wrote: > > Eh, my school never 'ad an electronics class, nor a computer neither. Made > programming a bit tricky; we 'ad to write programs on a form and send 'em > off to next county. None of this new-fangled VHDL neither, we 'ad to do our > simulations with paper and pencil. > We dreamed of writing programs on a form. We had to make Hollerith punch cards by hand using a dull knife. You tell that to the kids of today and they won't believe you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Even Older Man Yells At Whippersnappers
On Wed, Sep 20, 2017 at 5:09 AM, Gregory Ewing wrote: > > Never mind that fake assembly rubbish, learn a real assembly > language! And hand-assemble it and toggle it into the front > panel switches like I did! 1979, I was working at Bausch and Lomb in Rochester NY. We had a 16 bit Data General Nova 'Minicomputer'. It had 4 registers, called accumulators. It had 16 front panel toggle switches, one for each bit, one that said 'deposit', and one that said run. It had a dial with stops for AC0, AC1, AC2, AC3 (for the 4 accumulators), PC (program counter), address and contents. When you powered up the machine it did not boot. You had to hand enter a short bootstrap program in binary. Do to this you had to turn the dial to address, key in a 16 bit address, click deposit, turn the dial to contents, key in a 16 bit line of assembly code, click deposit, and repeat this for each line of code (there were like 5 or 6). Then key in the address of where you wanted to run from turn the dial to PC, deposit, and click run. Any mistake and it would not boot. Often took 3 or 4 tries. After a few weeks of this I was sick of it. I had the boot code burned into an EEPROM (which I had to send out to be programmed). Then I build a very small wire wrapped board with the EEPROM and an oscillator and few TTL chips. I tapped into the 5V power on the CPU board and used the leading edge of that to trigger a one shot which 'woke up' my circuit, and caused it to clock out the code from the EEPROM and load it to the appropriate place, set the program counter and start the program. I drilled holes in the CPU board and mounted this with little plastic standoffs. I did this all on my own, coming in on the weekends, without company approval, and when it was working I showed my boss. He was blown away and he was sure we could patent this and sell it. He had me formalize the design, write it up, have an actual PCB made, go to the company lawyers, the whole 9 yards. Then Data General announced the new version of the Nova with auto boot. -- https://mail.python.org/mailman/listinfo/python-list
Re: Beginners and experts (Batchelder blog post)
On Wed, Sep 27, 2017 at 12:41 PM, leam hall wrote: > 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. Fake it till you make it! -- https://mail.python.org/mailman/listinfo/python-list
Re: Beginners and experts (Batchelder blog post)
On Thu, Sep 28, 2017 at 5:08 PM, Chris Angelico wrote: > Yep. Pick anyone on this list that you believe is an expert, and ask > him/her for a story of a long debug session that ended up finding a > tiny problem. I can pretty much guarantee that every expert programmer > will have multiple such experiences, and it's just a matter of > remembering one with enough detail to share the story. The software development process can be summed up thusly: I can’t fix this Crisis of confidence Questions career Questions life Oh it was a typo, cool -- https://mail.python.org/mailman/listinfo/python-list
zlib OverflowError: 'size does not fit in an int'
Trying to zip a large file is failing with OverflowError: 'size does not fit in an int'. Googling I found this: https://bugs.python.org/issue23306 and this: https://hg.python.org/cpython/rev/2192edcfea02 which seems to make me think this was fixed this was fixed on Jul 23 2016. I am running CentOS 7 and I have python version: Python 2.7.5 (default, Sep 15 2016, 22:37:39) Which I guess does not have this fix. How can I get a version with that fix (that doesn't break CentOS) -- https://mail.python.org/mailman/listinfo/python-list
Re: zlib OverflowError: 'size does not fit in an int'
On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: > On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell > wrote: >> Trying to zip a large file is failing with OverflowError: 'size does >> not fit in an int'. Googling I found this: >> >> https://bugs.python.org/issue23306 >> >> and this: >> >> https://hg.python.org/cpython/rev/2192edcfea02 >> >> which seems to make me think this was fixed this was fixed on Jul 23 2016. >> >> I am running CentOS 7 and I have python version: >> >> Python 2.7.5 (default, Sep 15 2016, 22:37:39) >> >> Which I guess does not have this fix. How can I get a version with >> that fix (that doesn't break CentOS) > > First thing I'd consider is a Python 3.x version. Is there one in your > CentOS repositories? If not, worst case, you can compile one from > source or get one from some other repo, and it can't possibly break > your system because it won't mess with anything you're using. > > If you absolutely HAVE to stick with 2.7, you may do well to compile > from source and NOT install - just run the binary from the source > directory. This is a django app, using version 1.9, installed on many sites that do not have external internet access, so any changes are onerous. Possible, but a PITA. I will look into building from source. -- https://mail.python.org/mailman/listinfo/python-list
Re: zlib OverflowError: 'size does not fit in an int'
On Mon, Dec 4, 2017 at 7:36 PM, Thomas Jollans wrote: > On 05/12/17 01:21, Larry Martell wrote: >> On Mon, Dec 4, 2017 at 7:15 PM, Chris Angelico wrote: >>> On Tue, Dec 5, 2017 at 10:46 AM, Larry Martell >>> wrote: >>>> Trying to zip a large file is failing with OverflowError: 'size does >>>> not fit in an int'. Googling I found this: >>>> >>>> https://bugs.python.org/issue23306 >>>> >>>> and this: >>>> >>>> https://hg.python.org/cpython/rev/2192edcfea02 >>>> >>>> which seems to make me think this was fixed this was fixed on Jul 23 2016. >>>> >>>> I am running CentOS 7 and I have python version: >>>> >>>> Python 2.7.5 (default, Sep 15 2016, 22:37:39) >>>> >>>> Which I guess does not have this fix. How can I get a version with >>>> that fix (that doesn't break CentOS) >>> >>> First thing I'd consider is a Python 3.x version. Is there one in your >>> CentOS repositories? If not, worst case, you can compile one from >>> source or get one from some other repo, and it can't possibly break >>> your system because it won't mess with anything you're using. >>> >>> If you absolutely HAVE to stick with 2.7, you may do well to compile >>> from source and NOT install - just run the binary from the source >>> directory. >> >> This is a django app, using version 1.9, installed on many sites that >> do not have external internet access, so any changes are onerous. >> Possible, but a PITA. I will look into building from source. >> > > FWIW, there is also an SCL with a newer version of Python 2.7 (loathe as > I am to point it out) > > See also: https://pythonclock.org/ Where is there a link on that page to download a new version of 2.7? -- https://mail.python.org/mailman/listinfo/python-list
Re: SystemError: error return without exception set
On Thu, Dec 7, 2017 at 10:36 AM, Natalie Leung wrote: > I am trying to use Python to communicate and send commands in MSC Marc. A > part of the code looks something like this: > > from py_mentat import* > > directory = '[specified the file path to my model]' > marcModel = '[name of my model]' > > py_echo(0) > openModel = '*new_model yes *open_model "'+ directory + marcModel +'"' > py_send(openModel) > > > The code stops at "py_send(openModel)" with an error message that reads: > Traceback (most recent call last): File "[my file path]", line 11, in > py_send(openModel) > SystemError: error return without exception set > > I tried running the code on different platforms (e.g. Command Prompt, Wing > 101, python.exe) and I get the same result. What could be the problem? Faced with this I would use the debugger to break on the py_send line and then step into that function, and then step through it, e.g.: python -m pdb your_script.py b 8 [ or whatever the py_send line is) c [to continue to the BP) s [to step into py_send] then step through the function and something more informative may be revealed. -- https://mail.python.org/mailman/listinfo/python-list
scipy
Trying to install scipy on ubuntu-trusty-64 running Python 2.7.6. It's failing with: $ sudo pip install scipy Downloading/unpacking scipy Downloading scipy-1.0.0.tar.gz (15.2MB): 15.2MB downloaded Running setup.py (path:/tmp/pip_build_root/scipy/setup.py) egg_info for package scipy /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires' Followed by many screens full of errors. Is that just a warning or is that the issue? I've installed many other packages without a problem on this same system. What is the issue here? -- https://mail.python.org/mailman/listinfo/python-list
Re: scipy
On Sat, Dec 9, 2017 at 11:43 AM, Thomas Jollans wrote: > > On 08/12/17 23:57, Larry Martell wrote: > > Trying to install scipy on ubuntu-trusty-64 running Python 2.7.6. > > I STRONGLY recommend moving to Python 3 if you can. The scientific > python ecosystem has had good support for Python 3 for years now. Many > scientific packages, including numpy (the king of scientific > Pythonland), have decided to drop official Python 2 support fairly soon; > numpy will not release any new versions for Python 2 after 2018. It's not in my control. This is part of a django app that is deployed it many sites all over the world, and my customer wants to make as few changes as possible. > > It's failing with: > > > > $ sudo pip install scipy > > Downloading/unpacking scipy > > Downloading scipy-1.0.0.tar.gz (15.2MB): 15.2MB downloaded > > Running setup.py (path:/tmp/pip_build_root/scipy/setup.py) egg_info > > for package scipy > > /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown > > distribution option: 'python_requires' > > > > Followed by many screens full of errors. Is that just a warning or is > > that the issue? I've installed many other packages without a problem > > on this same system. What is the issue here? > > > > I'm just guessing here, but do you have the latest versions of > distutils, setuptools and pip? It's likely that scipy requires newer > versions of these than your distribution provides. You may have to > upgrade them. I resolved this by installing a newer version of pip. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Learning
On Sun, Dec 17, 2017 at 4:18 PM, Chris Angelico wrote: > On Mon, Dec 18, 2017 at 6:51 AM, Bill wrote: >> The point is that it takes a certain amount of what is referred to as >> "mathematical maturity" (not mathematical knowledge) to digest a book >> concerning computer programming. > > Emphasis on *a book*. > >> In my years of teaching experience, >> students who came to college without the equivalent of "college algebra" >> were under-prepared for what was expected of them. This is not just an >> opinion, it's a fact. > > So, your experience is that the style of learning you offer is > unsuitable to anyone who doesn't have some background in algebra. > That's fine. For your course, you set the prereqs. But that's not the > only way for someone to get into coding. You do NOT have to go to > college before you start creating software. That is also not an > opinion; it's a fact backed by a number of proven instances (myself > included). I started coding when I was 16, in 1975. I wrote a downhill skiing game in basic, which I had taught to myself. I went to collage when I was 17, and I had taught myself FORTRAN and I tested out of the class. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Learning
On Mon, Dec 18, 2017 at 9:09 AM, Rhodri James wrote: > On 18/12/17 13:28, Marko Rauhamaa wrote: >> >> However, I have been doing quite a bit of hiring, quite successfully, I >> might add. I am not prejudiced one way or another. Your résumé doesn't >> count. Your education doesn't count. What you can do for the team >> counts, and that is measured during the interview process. > > > While I agree with most of what you say, I disagree with you here. Your CV > (résumé) does count, just not necessarily in the way most people expect. > > I haven't often been involved in hiring, but the few times I have we had > more applicants than it was feasible to interview. We used CVs as the only > thing we had to filter with, looking for *interesting* people. Exactly what > "interesting" meant was somewhat arbitrary; we put one person through to > interview because she was a cellist, and that would have given us a complete > string quartet (she didn't get the job, sadly). Yes, I once chose to interview someone because he had on his resume that he was an award winning duck decoy carver. He also did not get the job. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Learning
On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: > However, one great way to stand out is a portfolio of GitHub projects. > Several people have gotten an offer largely based on those (after they > aced the technical interviews). For example, we just hired someone who > had written a game in sed. That doesn't make him an "interesting > person," nor do we look for game or sed developers. But that silly > exercise deeply resonated with our team. We expect to have great synergy > with him. I have been excluded from even getting an interview because I did not have a portfolio of GitHub projects. I think that is a bad filter. I work 60-70 hours a week for pay, and I have a family and personal interests. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Learning
On Mon, Dec 18, 2017 at 12:05 PM, Chris Angelico wrote: > On Tue, Dec 19, 2017 at 3:45 AM, Larry Martell > wrote: >> On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: >>> However, one great way to stand out is a portfolio of GitHub projects. >>> Several people have gotten an offer largely based on those (after they >>> aced the technical interviews). For example, we just hired someone who >>> had written a game in sed. That doesn't make him an "interesting >>> person," nor do we look for game or sed developers. But that silly >>> exercise deeply resonated with our team. We expect to have great synergy >>> with him. >> >> I have been excluded from even getting an interview because I did not >> have a portfolio of GitHub projects. I think that is a bad filter. I >> work 60-70 hours a week for pay, and I have a family and personal >> interests. > > Maybe not GitHub, but something else. Do you have, anywhere on the > internet, a list of demo-worthy projects? Again drawing from the > students I work with, they're encouraged to build an actual portfolio > web site. Granted, they *are* full stack web developers, so this may > not be applicable to everyone, but still, it's independent of GitHub. Nothing I can put on the internet because the work I have done is either an embedded system or proprietary and used in house for a company, or part of a commercial project. I do have things I can show from my machine using my development environment, and I have offered that up, but for those who want to see something on GitHub it does not get that far. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Learning
On Mon, Dec 18, 2017 at 4:05 PM, Rob Gaddi wrote: > On 12/18/2017 08:45 AM, Larry Martell wrote: >> >> On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: >>> >>> However, one great way to stand out is a portfolio of GitHub projects. >>> Several people have gotten an offer largely based on those (after they >>> aced the technical interviews). For example, we just hired someone who >>> had written a game in sed. That doesn't make him an "interesting >>> person," nor do we look for game or sed developers. But that silly >>> exercise deeply resonated with our team. We expect to have great synergy >>> with him. >> >> >> I have been excluded from even getting an interview because I did not >> have a portfolio of GitHub projects. I think that is a bad filter. I >> work 60-70 hours a week for pay, and I have a family and personal >> interests. >> > > When I'm hiring I don't necessarily need a candidate to have an extensive > open-source portfolio, but I need to see some kind of portfolio, just as a > bar of "This is what I consider my good work to be." The idea that someone > is going to have years of experience, but not a single page of code that > they can let me look over always strikes me as odd. I have lots of code and projects to show, but only on my computer. I once got a django/python job because I had a PHP app I did to show. But if they had not interviewed me because I had nothing on a public site they never would have seen it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Learning
On Mon, Dec 18, 2017 at 4:52 PM, Gene Heskett wrote: > On Monday 18 December 2017 16:05:10 Rob Gaddi wrote: > >> On 12/18/2017 08:45 AM, Larry Martell wrote: >> > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa > wrote: >> >> However, one great way to stand out is a portfolio of GitHub >> >> projects. Several people have gotten an offer largely based on >> >> those (after they aced the technical interviews). For example, we >> >> just hired someone who had written a game in sed. That doesn't make >> >> him an "interesting person," nor do we look for game or sed >> >> developers. But that silly exercise deeply resonated with our team. >> >> We expect to have great synergy with him. >> > >> > I have been excluded from even getting an interview because I did >> > not have a portfolio of GitHub projects. I think that is a bad >> > filter. I work 60-70 hours a week for pay, and I have a family and >> > personal interests. >> >> When I'm hiring I don't necessarily need a candidate to have an >> extensive open-source portfolio, but I need to see some kind of >> portfolio, just as a bar of "This is what I consider my good work to >> be." The idea that someone is going to have years of experience, but >> not a single page of code that they can let me look over always >> strikes me as odd. > > I've known Larry for years via another list. He has worked on a lot of > stuff in the financial arena, wrapped in non-disclosure clauses that > prevent him from even saying what color he dots the i's with, so he gets > work as much by word of mouth as other more conventional paths. True story. > To not hire him because he doesn't have a big portfolio could be a > mistake, Rob. Its up to you. Thank you my friend. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Learning
On Mon, Dec 18, 2017 at 3:22 PM, Marko Rauhamaa wrote: > > Larry Martell : > > > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa wrote: > >> However, one great way to stand out is a portfolio of GitHub > >> projects. Several people have gotten an offer largely based on those > >> (after they aced the technical interviews). For example, we just > >> hired someone who had written a game in sed. That doesn't make him an > >> "interesting person," nor do we look for game or sed developers. But > >> that silly exercise deeply resonated with our team. We expect to have > >> great synergy with him. > > > > I have been excluded from even getting an interview because I did not > > have a portfolio of GitHub projects. I think that is a bad filter. I > > work 60-70 hours a week for pay, and I have a family and personal > > interests. > > Personal programming projects are not a requirement. They are just a > very effective advertising tool. > > As for 60—70 hours a week... sounds horrible. My sympathies. Nah - I get paid by the hour and I love what I do. -- https://mail.python.org/mailman/listinfo/python-list
Re: has sourceforge exposed the dirty little secret ?
On Fri, Jan 5, 2018 at 11:27 AM, Kim of K. wrote: > > "Background > > We feel that the world still produces way too much software that is > frankly substandard. The reasons for this are pretty simple: software > producers do not pay enough attention [...]" > > > quote from http://texttest.sourceforge.net/index.php?page=about > > > In other words: most sites like SF and github offer tons of crap. > download and break is the overwhelming theme here. > > why is no one complaining ? You want to complain? Look at these shoes. I've only had them three weeks and the heels are worn right through. -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple graphic library for beginners
On Wed, Jan 10, 2018 at 7:42 AM Jan Erik Moström wrote: > I'm looking for a really easy to use graphic library. The target users > are teachers who have never programmed before and is taking a first (and > possible last) programming course. > > I would like to have the ability to draw lines, circles, etc. Nothing > fancy, as little window management as possible (possible buttons), > perhaps simple events like button presses or clicks on canvas - think: > making simple diagrams or simple figures. Cross-platform > > > Yes, I know about tkinter. > > Yes, I know about various block languages like Scratch but they are not > relevant in this case. > > Any suggestions? > I really like plotly. > > -- https://mail.python.org/mailman/listinfo/python-list
documentation on read.encode
Looking for 2.7 docs on read.encode - googling did not turn up anything. Specifically, looking for the supported options for base64, and how to specify them, e.g. Base64.NO_WRAP -- https://mail.python.org/mailman/listinfo/python-list
Re: documentation on read.encode
On Tue, Jan 16, 2018 at 12:00 PM, Larry Martell wrote: > Looking for 2.7 docs on read.encode - googling did not turn up anything. > > Specifically, looking for the supported options for base64, and how to > specify them, e.g. Base64.NO_WRAP So I just realized that encode() is not a method of read() it's a string method. But I still have the same question - can I pass in any flags? My issue is that I am base64 encoding PNG images on linux and it's putting a LF at the end of each line. If I do the same on Windows it's putting CR/LF. I want the files to be encoded with no platform dependences. Googling I found mention of Base64.NO_WRAP and I want to pass that into encode() - can I do that? -- https://mail.python.org/mailman/listinfo/python-list
Re: documentation on read.encode
On Tue, Jan 16, 2018 at 2:35 PM, Gene Heskett wrote: > On Tuesday 16 January 2018 14:19:38 Larry Martell wrote: > >> On Tue, Jan 16, 2018 at 12:00 PM, Larry Martell > wrote: >> > Looking for 2.7 docs on read.encode - googling did not turn up >> > anything. >> > >> > Specifically, looking for the supported options for base64, and how >> > to specify them, e.g. Base64.NO_WRAP >> >> So I just realized that encode() is not a method of read() it's a >> string method. But I still have the same question - can I pass in any >> flags? >> >> My issue is that I am base64 encoding PNG images on linux and it's >> putting a LF at the end of each line. If I do the same on Windows it's >> putting CR/LF. I want the files to be encoded with no platform >> dependences. Googling I found mention of Base64.NO_WRAP and I want to >> pass that into encode() - can I do that? > > Di you not have the manpages installed? > > In my copy of the manpage: > base64 [OPTION]... [FILE] > where option is: > -w, --wrap=COLS > wrap encoded lines after COLS character (default 76). Use > 0 to disable line wrapping. > > Seems pretty simple. But how do I use that in read().encode('base64')? -- https://mail.python.org/mailman/listinfo/python-list
Re: documentation on read.encode
On Tue, Jan 16, 2018 at 3:17 PM, Ned Batchelder wrote: > On 1/16/18 2:19 PM, Larry Martell wrote: >> >> On Tue, Jan 16, 2018 at 12:00 PM, Larry Martell >> wrote: >>> >>> Looking for 2.7 docs on read.encode - googling did not turn up anything. >>> >>> Specifically, looking for the supported options for base64, and how to >>> specify them, e.g. Base64.NO_WRAP >> >> So I just realized that encode() is not a method of read() it's a >> string method. But I still have the same question - can I pass in any >> flags? >> >> My issue is that I am base64 encoding PNG images on linux and it's >> putting a LF at the end of each line. If I do the same on Windows it's >> putting CR/LF. I want the files to be encoded with no platform >> dependences. Googling I found mention of Base64.NO_WRAP and I want to >> pass that into encode() - can I do that? > > > Base64.NO_WRAP seems to be a Java thing. Yeah I saw it mentioned in a SO post that was java related. Wondering if there is some way to do the same in python. -- https://mail.python.org/mailman/listinfo/python-list
Re: documentation on read.encode
On Tue, Jan 16, 2018 at 3:58 PM, MRAB wrote: > On 2018-01-16 19:52, Larry Martell wrote: >> >> On Tue, Jan 16, 2018 at 2:35 PM, Gene Heskett >> wrote: >>> >>> On Tuesday 16 January 2018 14:19:38 Larry Martell wrote: >>> >>>> On Tue, Jan 16, 2018 at 12:00 PM, Larry Martell >>> >>> wrote: >>>> >>>> > Looking for 2.7 docs on read.encode - googling did not turn up >>>> > anything. >>>> > >>>> > Specifically, looking for the supported options for base64, and how >>>> > to specify them, e.g. Base64.NO_WRAP >>>> >>>> So I just realized that encode() is not a method of read() it's a >>>> string method. But I still have the same question - can I pass in any >>>> flags? >>>> >>>> My issue is that I am base64 encoding PNG images on linux and it's >>>> putting a LF at the end of each line. If I do the same on Windows it's >>>> putting CR/LF. I want the files to be encoded with no platform >>>> dependences. Googling I found mention of Base64.NO_WRAP and I want to >>>> pass that into encode() - can I do that? >>> >>> >>> Di you not have the manpages installed? >>> >>> In my copy of the manpage: >>> base64 [OPTION]... [FILE] >>> where option is: >>> -w, --wrap=COLS >>> wrap encoded lines after COLS character (default 76). Use >>> 0 to disable line wrapping. >>> >>> Seems pretty simple. >> >> >> But how do I use that in read().encode('base64')? >> > Use the base64 module instead, which is also how you would do it in Python > 3. > > If you're getting CR/LF on Windows, that's because you're opening the file > in text mode. In both Python 2 and Python 3 the base64 string will be a > bytestring, which you'd write out to a file opened in binary mode. > > That's an extra bit of future-proofing! :-) Thanks. That's what it ended up being. The code that was receiving the PNG was not reading and writing the file as binary. Strangely that worked on Linux but not on Windows. -- https://mail.python.org/mailman/listinfo/python-list
Re: documentation on read.encode
On Thu, Jan 18, 2018 at 12:47 AM, Steven D'Aprano wrote: > On Wed, 17 Jan 2018 16:54:37 -0500, Larry Martell wrote: > >> The code that was receiving the >> PNG was not reading and writing the file as binary. Strangely that >> worked on Linux but not on Windows. > > Nothing strange about it -- on Unix and Linux systems (with the possible > exception of Mac OS?) in Python 2 there's no difference between text and > binary mode for ASCII-only files. In Python 2, strings are byte strings, > not Unicode, and reading from files returns such sequences of bytes. > > On Windows, reading from files in text mode treats \r\n as the end of > line, and converts[1] such \r\n pairs to \n; it also treats ^Z byte as > the end of file[2], or at least it used to back in the 2.5 or so days. I > haven't tested it in more recent versions. > > > [1] Technically this is a build-time option, but as far as I know it is > not just the default but pretty much universal. > > [2] https://blogs.msdn.microsoft.com/oldnewthing/20040316-00/?p=40233/ Thanks for the clarification. I have been programming since 1975 and thankfully have had very little exposure to Windows. -- https://mail.python.org/mailman/listinfo/python-list
error from Popen only when run from cron
I have a script that does this: subprocess.Popen(['service', 'some_service', 'status'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) When I run it from the command line it works fine. When I run it from cron I get: subprocess.Popen(['service', 'some_service', 'status'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__ errread, errwrite) File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory Anyone have any clue as to what file it's complaining about? Or how I can debug this further? -- https://mail.python.org/mailman/listinfo/python-list
Re: error from Popen only when run from cron
On Sat, Jan 27, 2018 at 11:09 AM, Chris Angelico wrote: > On Sun, Jan 28, 2018 at 2:58 AM, Larry Martell > wrote: >> I have a script that does this: >> >> subprocess.Popen(['service', 'some_service', 'status'], >> stdout=subprocess.PIPE, stderr=subprocess.STDOUT) >> >> When I run it from the command line it works fine. When I run it from >> cron I get: >> >> subprocess.Popen(['service', 'some_service', 'status'], >> stdout=subprocess.PIPE, stderr=subprocess.STDOUT) >> File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__ >> errread, errwrite) >> File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child >> raise child_exception >> OSError: [Errno 2] No such file or directory >> >> Anyone have any clue as to what file it's complaining about? Or how I >> can debug this further? > > Looks like you're trying to invoke a process without a full path? It > could be because cron jobs execute in a restricted environment. Two > things to try: > > 1) Dump out os.environ to a file somewhere (maybe in /tmp if you don't > have write permission). See if $PATH is set to some really short > value, or at least to something different from what you see when you > run it outside of cron. > > 2) Replace the word "service" with whatever you get from running > "which service" on your system. On mine, it's "/usr/sbin/service". See > what that does. > > Might not solve your problem, but it's worth a try. Thanks! Using the full path fixed the issue. -- https://mail.python.org/mailman/listinfo/python-list
Re: Where has the practice of sending screen shots as source code come from?
On Sun, Jan 28, 2018 at 10:04 AM, Steven D'Aprano wrote: > I'm seeing this annoying practice more and more often. Even for trivial > pieces of text, a few lines, people post screenshots instead of copying > the code. > > Where has this meme come from? It seems to be one which inconveniences > *everyone* involved: > > - for the sender, instead of a simple copy and paste, they have to take a > screen shot, possibly trim the image to remove any bits of the screen > they don't want to show, attach it to their email or upload it to an > image hosting site; > > - for the receiver, you are reliant on a forum which doesn't strip > attachments, or displays externally hosted images; the visually impaired > are excluded from using a screen reader; and nobody can copy or edit the > given text. > > It is as if people are deliberately inconveniencing themselves in order > to inconvenience the people they are asking to help them. > > With the exception of one *exceedingly* overrated advantage, namely the > ability to annotate the image with coloured lines and circles and > squiggles or other graphics (which most people don't bother to do), this > seems to me to be 100% counter-productive for everyone involved. Why has > it spread and why do people keep doing it? > > I don't want to be the old man yelling "Get Of My Lawn!" to the cool > kids, but is this just another sign of the downward spiral of programming > talent? Convince me that there is *some* justification for this practice. > Even a tiny one. > > (The day a programmer posts a WAV file of themselves reading their code > out aloud, is the day I turn my modem off and leave the internet forever.) I work remotely and have for over 20 years. At first I communicated with my colleagues via phone and email. Then it was skype for a while but then it went back to email. Then IRC had a moment, then it was slack for a while, then back to email. Now everyone seems to be switching to google hangouts, both chat and video. Recently I have seen that some people are sending screen shots of their code and/or error messages instead of copy/pasting. It's mostly with the younger ones, and I do not care for it at all, but I did not want to be the old fogy, so I did not say anything. -- https://mail.python.org/mailman/listinfo/python-list
Re: This newsgroup (comp.lang.python) may soon be blocked by Google Gro
On Thu, Feb 8, 2018 at 12:36 PM, Gilmeh Serda wrote: > On Sat, 03 Feb 2018 04:33:36 +1200, breamoreboy wrote: > >>> When trying to access comp.lang.idl-pvwave, a message is now displayed, >> stating that the group owner needs to remove the spam, and can then >> apply to Google in order to have access reinstated. > > Just as I have always suspected: Google are run by idiots! Very, very rich idiots. -- https://mail.python.org/mailman/listinfo/python-list
atws
I want to use the atws package (https://atws.readthedocs.io/readme.html). I am using python 2.7.6 on ubuntu-trusty-64 3.13.0-87-generic. I get this error when importing the package: >>> import atws Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/atws/__init__.py", line 4, in from .wrapper import connect File "/usr/local/lib/python2.7/dist-packages/atws/wrapper.py", line 32, in from . import connection File "/usr/local/lib/python2.7/dist-packages/atws/connection.py", line 19, in from requests.exceptions import ConnectTimeout, Timeout, ReadTimeout, SSLError ImportError: cannot import name ConnectTimeout I would not be surprised if no one here has used this package, but has anyone seen this error in other packages or their own work? -- https://mail.python.org/mailman/listinfo/python-list
Re: atws
On Thu, Feb 22, 2018 at 2:00 AM, Chris Angelico wrote: > On Thu, Feb 22, 2018 at 5:27 PM, Larry Martell > wrote: >> I want to use the atws package >> (https://atws.readthedocs.io/readme.html). I am using python 2.7.6 on >> ubuntu-trusty-64 3.13.0-87-generic. I get this error when importing >> the package: >> >>>>> import atws >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/local/lib/python2.7/dist-packages/atws/__init__.py", line >> 4, in >> from .wrapper import connect >> File "/usr/local/lib/python2.7/dist-packages/atws/wrapper.py", line >> 32, in >> from . import connection >> File "/usr/local/lib/python2.7/dist-packages/atws/connection.py", >> line 19, in >> from requests.exceptions import ConnectTimeout, Timeout, >> ReadTimeout, SSLError >> ImportError: cannot import name ConnectTimeout >> >> I would not be surprised if no one here has used this package, but has >> anyone seen this error in other packages or their own work? > > You're running that on a fairly old version of Python (2.7.6 - the > latest in the 2.x branch is 2.7.14). It's entirely possible that the > app doesn't support the versions of Python and/or the 'requests' > library that you have installed. > > First thing to try: can you use the app under Python 3? This is a mature django app and I cannot switch to Python 3. > For reference, here's the version of requests that I have (which does > have that exception available): > >>>> import requests >>>> requests.__version__ > '2.18.4' > > What's yours? I had 2.2.1. I updated requests to 2.18.4 and now when I import atws I get: No handlers could be found for logger "atws.connection" -- https://mail.python.org/mailman/listinfo/python-list
Re: atws
On Thu, Feb 22, 2018 at 10:25 AM, Mark Lawrence wrote: > On 22/02/18 15:06, Larry Martell wrote: >> >> On Thu, Feb 22, 2018 at 2:00 AM, Chris Angelico wrote: >>> >>> On Thu, Feb 22, 2018 at 5:27 PM, Larry Martell >>> wrote: >>>> >>>> I want to use the atws package >>>> (https://atws.readthedocs.io/readme.html). I am using python 2.7.6 on >>>> ubuntu-trusty-64 3.13.0-87-generic. I get this error when importing >>>> the package: >>>> >>>>>>> import atws >>>> >>>> Traceback (most recent call last): >>>>File "", line 1, in >>>>File "/usr/local/lib/python2.7/dist-packages/atws/__init__.py", line >>>> 4, in >>>> from .wrapper import connect >>>>File "/usr/local/lib/python2.7/dist-packages/atws/wrapper.py", line >>>> 32, in >>>> from . import connection >>>>File "/usr/local/lib/python2.7/dist-packages/atws/connection.py", >>>> line 19, in >>>> from requests.exceptions import ConnectTimeout, Timeout, >>>> ReadTimeout, SSLError >>>> ImportError: cannot import name ConnectTimeout >>>> >>>> I would not be surprised if no one here has used this package, but has >>>> anyone seen this error in other packages or their own work? >>> >>> >>> You're running that on a fairly old version of Python (2.7.6 - the >>> latest in the 2.x branch is 2.7.14). It's entirely possible that the >>> app doesn't support the versions of Python and/or the 'requests' >>> library that you have installed. >>> >>> First thing to try: can you use the app under Python 3? >> >> >> This is a mature django app and I cannot switch to Python 3. >> >>> For reference, here's the version of requests that I have (which does >>> have that exception available): >>> >>>>>> import requests >>>>>> requests.__version__ >>> >>> '2.18.4' >>> >>> What's yours? >> >> >> I had 2.2.1. I updated requests to 2.18.4 and now when I import atws I >> get: >> >> No handlers could be found for logger "atws.connection" >> > > I get exactly the same thing, but do the import interactively and then > help(atws) shows help so I'm guessing that it's just a poor informational > message, so I suggest that you just try running your code and see what > happens. Thanks - it seems to work despite that message. > p.s. enjoying the curling at the Winter Olympics? For sure - huge upset over Canada! I stayed up until 3am watching the women's hockey game last night and I had to be up at 6 this morning, so I'm dragging now. -- https://mail.python.org/mailman/listinfo/python-list
Re: atws
On Fri, Feb 23, 2018 at 2:01 AM, dieter wrote: > Larry Martell writes: >> ... >> I had 2.2.1. I updated requests to 2.18.4 and now when I import atws I get: >> >> No handlers could be found for logger "atws.connection" > > This is a warning (only), telling you that the "atws" package wants > to log a message but there is not corresponding logging handler > defined -- likely because you did not configure Python's logging > infrastructure (--> "logging" package in Python's standard documentation). Yes, but this message comes from the import, which happens before any of my code runs. -- https://mail.python.org/mailman/listinfo/python-list
Re: atws
On Fri, Feb 23, 2018 at 8:34 AM, Chris Angelico wrote: > On Sat, Feb 24, 2018 at 12:08 AM, Larry Martell > wrote: >> On Fri, Feb 23, 2018 at 2:01 AM, dieter wrote: >>> Larry Martell writes: >>>> ... >>>> I had 2.2.1. I updated requests to 2.18.4 and now when I import atws I get: >>>> >>>> No handlers could be found for logger "atws.connection" >>> >>> This is a warning (only), telling you that the "atws" package wants >>> to log a message but there is not corresponding logging handler >>> defined -- likely because you did not configure Python's logging >>> infrastructure (--> "logging" package in Python's standard documentation). >> >> Yes, but this message comes from the import, which happens before any >> of my code runs. > > It's perfectly legal to put other code before an import: > > import logging > logging.basicConfig(...) > import atws > > But this is just a warning, so it's not that big a deal either way. Yes, I know it's legal, but I've always thought it was bad form. -- https://mail.python.org/mailman/listinfo/python-list
Re: help me ?
On Tue, Feb 27, 2018 at 12:56 PM, Ian Kelly wrote: > On Tue, Feb 27, 2018 at 10:16 AM, Igor Korot wrote: >> Congratulations! >> You have an "A" for solving the problem and "F" for helping the guy cheat. >> You should be expelled from the course. > > In my experience, this is what happens pretty much every time. > Somebody posts a homework question asking for the answer, a few people > say something to the effect of, "This looks like homework. What have > you tried so far?" Then some other bozo comes along who just likes > solving easy problems and hands up the answer on a silver platter. > > Cheaters are gonna cheat. In the unlikely event they don't get the > answer here, they'll probably just manage to convince somebody to do > the work for them somewhere else. Honestly, I don't know if it's even > worth the bother to engage. When I was in college back in the 70's they made people in majors like printing or chemistry, for example, take 1 programming course. They were always clueless and I often wrote programs for them - my typical fee was a case of beer. -- https://mail.python.org/mailman/listinfo/python-list
psutil
Trying to install psutil (with pip install psutil) on Red Hat EL 7. It's failing with: Python.h: No such file or directory Typically that means the python devel libs are not installed, but they are: [root@liszt ~]# yum install python-devel Package python-devel-2.7.5-58.el7.x86_64 already installed and latest version Nothing to do Anyone have any idea what to try next? -- https://mail.python.org/mailman/listinfo/python-list
Re: psutil
On Tue, Feb 27, 2018 at 7:37 PM, Chris Angelico wrote: > On Wed, Feb 28, 2018 at 11:29 AM, Larry Martell > wrote: >> Trying to install psutil (with pip install psutil) on Red Hat EL 7. >> It's failing with: >> >> Python.h: No such file or directory >> >> Typically that means the python devel libs are not installed, but they are: >> >> [root@liszt ~]# yum install python-devel >> Package python-devel-2.7.5-58.el7.x86_64 already installed and latest version >> Nothing to do >> >> Anyone have any idea what to try next? > > Are you trying to install that into Python 3 or Python 2? Might need > to grab python3-devel. Python 2 -- https://mail.python.org/mailman/listinfo/python-list
Re: psutil
On Tue, Feb 27, 2018 at 7:36 PM, José María Mateos wrote: > On Tue, Feb 27, 2018 at 07:29:50PM -0500, Larry Martell wrote: >> Trying to install psutil (with pip install psutil) on Red Hat EL 7. >> It's failing with: >> >> Python.h: No such file or directory > > Two questions come to my mind: > > - Does it work if you try to install some other package? Yes, I have installed other packages (e.g. numpy) > - Is `pip` by any change trying to install a Python 3 package, but you > only have the libraries for Python 2 installed? No, here is the gcc command line that failed: gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=543 -DPSUTIL_LINUX=1 -I/opt/rh/python27/root/usr/include/python2.7 -c psutil/_psutil_common.c -o build/temp.linux-x86_64-2.7/psutil/_psutil_common.o -- https://mail.python.org/mailman/listinfo/python-list
Re: psutil
On Tue, Feb 27, 2018 at 8:30 PM, Matt Wheeler wrote: > > > On Wed, 28 Feb 2018, 00:49 Larry Martell, wrote: >> >> On Tue, Feb 27, 2018 at 7:36 PM, José María Mateos >> wrote: >> > On Tue, Feb 27, 2018 at 07:29:50PM -0500, Larry Martell wrote: >> >> Trying to install psutil (with pip install psutil) on Red Hat EL 7. >> >> It's failing with: >> >> >> >> Python.h: No such file or directory >> > >> > Two questions come to my mind: >> > >> > - Does it work if you try to install some other package? >> >> Yes, I have installed other packages (e.g. numpy) > > > Did that install definitely involve a build from source? > >> > - Is `pip` by any change trying to install a Python 3 package, but you >> > only have the libraries for Python 2 installed? >> >> No, here is the gcc command line that failed: >> >> gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall >> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong >> --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic >> -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall >> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong >> --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic >> -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 >> -DPSUTIL_VERSION=543 -DPSUTIL_LINUX=1 >> -I/opt/rh/python27/root/usr/include/python2.7 -c >> psutil/_psutil_common.c -o >> build/temp.linux-x86_64-2.7/psutil/_psutil_common.o > > > Based on the include path you have here this looks like you have a non > standard python package for EL7 (in addition to the system one, or you'd be > having a worse day), which is probably the root of your problem. > > Are you using python packages from scl perhaps? > If so you probably need to install python27-python-devel (found at > http://mirror.centos.org/centos/7/sclo/x86_64/rh/python27/) Thanks to all who replied. The machine got rebooted (for an unrelated issue) and when it came back up the install worked fine. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why no list as dict key?
On Wed, Apr 20, 2022 at 2:23 PM Abdur-Rahmaan Janhangeer wrote: > > Greetings list, > > Using Python3.9, i cannot assign a list [1, 2] as key > to a dictionary. Why is that so? Thanks in advanced! Dict keys cannot be mutable. Use a tuple instead. -- https://mail.python.org/mailman/listinfo/python-list
terminate called after throwing an instance of 'boost::python::error_already_set
I have a script that has literally been running for 10 years. Suddenly, for some runs it crashes with the error: terminate called after throwing an instance of 'boost::python::error_already_set No stack trace. Anyone have any thoughts on what could cause this and/or how I can track it down? -- https://mail.python.org/mailman/listinfo/python-list
Re: terminate called after throwing an instance of 'boost::python::error_already_set
On Fri, May 27, 2022 at 5:51 PM dn wrote: > On 28/05/2022 08.14, Larry Martell wrote: > > I have a script that has literally been running for 10 years. > > Suddenly, for some runs it crashes with the error: > > > > terminate called after throwing an instance of > 'boost::python::error_already_set > > > > No stack trace. Anyone have any thoughts on what could cause this > > and/or how I can track it down? > > 1 a change to Python interpreter being used > > 2 a change to the boost library being used > > 3 a change to lower levels in 'the s/w stack' or h/w > > 4 a change to the data being passed-across Definitely not 1. 4 is always the case - every run is with different data. 2 and 3 I don’t know. What is boost and how does Python use it? None of my code is importing it. How can get a stack trace when it crashes with just that message? > -- https://mail.python.org/mailman/listinfo/python-list
Re: Function to Print a nicely formatted Dictionary or List?
On Thu, Jun 9, 2022 at 11:44 AM Dave wrote: > > Hi, > > Before I write my own I wondering if anyone knows of a function that will > print a nicely formatted dictionary? > > By nicely formatted I mean not all on one line! >>> import json >>> d = {'John': 'Cleese', 'Eric': "Idle", 'Micheal': 'Palin'} >>> print(json.dumps(d, indent=4)) { "John": "Cleese", "Eric": "Idle", "Micheal": "Palin" } -- https://mail.python.org/mailman/listinfo/python-list
Re: flattening lists
On Tue, Oct 11, 2022 at 12:48 PM SquidBits _ wrote: > > Does anyone else think there should be a flatten () function, which just > turns a multi-dimensional list into a one-dimensional list in the order it's > in. e.g. > > [[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9]. > > I have had to flatten lists quite a few times and it's quite tedious to type > out. It feels like this should be something built in to python, anyone else > think this way? x = [[1,2,3],[4,5,6,7],[8,9]] [i for j in x for i in j] [1, 2, 3, 4, 5, 6, 7, 8, 9] -- https://mail.python.org/mailman/listinfo/python-list
Re: Rob Cliffe should stop sending me rude email messages.
On Sun, Feb 26, 2023 at 3:49 PM Hen Hanna wrote: > > Rob Cliffe should stop sending me rude email messages. You should stop spamming this lists with with meaningless posts. -- https://mail.python.org/mailman/listinfo/python-list
Re: TypeError: can only concatenate str (not "int") to str
On Sun, Feb 26, 2023 at 5:46 PM Chris Angelico wrote: > On Mon, 27 Feb 2023 at 12:44, MRAB wrote: > > Oh dear. An example of Godwin's Law. > > Yeah, is that finally enough to get this user banned ? I hope so > -- https://mail.python.org/mailman/listinfo/python-list
Re: comparing two lists
On Wed, Feb 24, 2021 at 4:45 PM Davor Levicki wrote: > > i have two lists > > list1 = ['01:15', 'abc', '01:15', 'def', '01:45', 'ghi' ] > list2 = ['01:15', 'abc', '01:15', 'uvz', '01:45', 'ghi' ] > > and when I loop through the list > > > list_difference = [] > for item in list1: > > if item not in list2: > list_difference.append(item) > > > and I managed to get the difference, but I need time as well > because it is a separate item and 'uvz' does not mean to me anything in the > list with a few thousand entries. > I tried to convert it to the dictionary, but it overwrites with last > key:value {'01:15' : 'def'} Instead of a list you could have a set of tuples and then just subtract them. -- https://mail.python.org/mailman/listinfo/python-list
Re: yield from () Was: Re: weirdness with list()
On Tue, Mar 2, 2021 at 2:16 PM Chris Angelico wrote: > > On Tue, Mar 2, 2021 at 5:51 AM Alan Gauld via Python-list > wrote: > > > > On 28/02/2021 00:17, Cameron Simpson wrote: > > > > > BUT... It also has a __iter__ value, which like any Box iterates over > > > the subboxes. For MDAT that is implemented like this: > > > > > > def __iter__(self): > > > yield from () > > > > Sorry, a bit OT but I'm curious. I haven't seen > > this before: > > > > yield from () > > > > What is it doing? > > What do the () represent in this context? > > > > It's yielding all the elements in an empty tuple. Which is none of > them, meaning that - for this simple example - iterating over the > object will produce zero results. I discovered something new (to me) yesterday. Was writing a unit test for generator function and I found that none of the function got executed at all until I iterated on the return value. It was blowing my mind as I was debugging the test and had a BP set in the first line of the function but it was not hit when I called the function. -- https://mail.python.org/mailman/listinfo/python-list
Best practices regarding PYTHONPATH
Which is considered better? Having a long import path or setting PYTHONPATH? For example, in a project where 50% of the imports come from the same top level directory is it better to add that dir to the path or reference it in the import statements? -- https://mail.python.org/mailman/listinfo/python-list
creating raw AWS log event
When an AWS cloudwatch event is passed to a consumer it looks like this: { "awslogs": { "data": "ewogICAgIm1l..." } } To get the actual message I do this: def _decode(data): compressed_payload = b64decode(data) json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) return json.loads(json_payload) message = _decode(json.dumps(event['awslogs']['data'])) This returns the log message as a string. For my unit tests I need to reverse this - given a message as a string I want to generate the compressed, encoded event structure. I have not been able to get this to work. I have this: message = b'test message' compressed= zlib.compress(message) event['awslogs']['data'] = str(compressed) message = _decode(json.dumps(event['awslogs']['data'])) Traceback (most recent call last): File "", line 1, in File "", line 3, in _decode zlib.error: Error -3 while decompressing data: incorrect header check Anyone see how to make this work? TIA! -- https://mail.python.org/mailman/listinfo/python-list
Re: creating raw AWS log event
On Wed, Jun 23, 2021 at 7:05 PM Dennis Lee Bieber wrote: > > On Wed, 23 Jun 2021 10:42:42 -0700, Larry Martell > declaimed the following: > > >def _decode(data): > >compressed_payload = b64decode(data) > >json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > >return json.loads(json_payload) > > > > >message = b'test message' > >compressed= zlib.compress(message) > >event['awslogs']['data'] = str(compressed) > > Where do you perform a B64 ENCODE operation? > > str() doesn't do that, it just converts the argument to a string which > may mean using escapes for non-printable bytes. B64 converts everything to > printable characters. Copy/paste fail. This is actually the code I tried: message = b'test message' compressed= zlib.compress(message) encoded = b64encode(compressed) event['awslogs']['data'] = str(encoded) message = _decode(json.dumps(event['awslogs']['data'])) -- https://mail.python.org/mailman/listinfo/python-list
Re: creating raw AWS log event
On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__pete...@web.de> wrote: > > On 23/06/2021 19:42, Larry Martell wrote: > > When an AWS cloudwatch event is passed to a consumer it looks like this: > > > > { > > "awslogs": { > > "data": "ewogICAgIm1l..." > > } > > } > > > > To get the actual message I do this: > > > > def _decode(data): > > compressed_payload = b64decode(data) > > json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > > return json.loads(json_payload) > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > > > This returns the log message as a string. > > > > For my unit tests I need to reverse this - given a message as a string > > I want to generate the compressed, encoded event structure. > > > > I have not been able to get this to work. I have this: > > > > message = b'test message' > > compressed= zlib.compress(message) > > event['awslogs']['data'] = str(compressed) > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > Traceback (most recent call last): > >File "", line 1, in > >File "", line 3, in _decode > > zlib.error: Error -3 while decompressing data: incorrect header check > > > > Anyone see how to make this work? > > The json/bas64 parts are not involved in the problem: > > >>> zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > Traceback (most recent call last): >File "", line 1, in > zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > zlib.error: Error -3 while decompressing data: incorrect header check > > whereas: > > >>> zlib.decompress(zlib.compress(b"foo")) > b'foo' > > Unfortunately compress() doesn't accept the flags you seem to require. > However, reading around a bit in the zlib docs turns up the compressobj > which does. So > > >>> def mycompress(data): > obj = zlib.compressobj(wbits=16 + zlib.MAX_WBITS) > result = obj.compress(data) > result += obj.flush() > return result > > >>> zlib.decompress(mycompress(b"foo"), 16 + zlib.MAX_WBITS) > b'foo' Thanks. Turns out I don't need this after all. -- https://mail.python.org/mailman/listinfo/python-list
Re: creating raw AWS log event
On Thu, Jun 24, 2021 at 10:38 AM Larry Martell wrote: > > On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__pete...@web.de> wrote: > > > > On 23/06/2021 19:42, Larry Martell wrote: > > > When an AWS cloudwatch event is passed to a consumer it looks like this: > > > > > > { > > > "awslogs": { > > > "data": "ewogICAgIm1l..." > > > } > > > } > > > > > > To get the actual message I do this: > > > > > > def _decode(data): > > > compressed_payload = b64decode(data) > > > json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > > > return json.loads(json_payload) > > > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > > > > > This returns the log message as a string. > > > > > > For my unit tests I need to reverse this - given a message as a string > > > I want to generate the compressed, encoded event structure. > > > > > > I have not been able to get this to work. I have this: > > > > > > message = b'test message' > > > compressed= zlib.compress(message) > > > event['awslogs']['data'] = str(compressed) > > > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > > Traceback (most recent call last): > > >File "", line 1, in > > >File "", line 3, in _decode > > > zlib.error: Error -3 while decompressing data: incorrect header check > > > > > > Anyone see how to make this work? > > > > The json/bas64 parts are not involved in the problem: > > > > >>> zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > > Traceback (most recent call last): > >File "", line 1, in > > zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > > zlib.error: Error -3 while decompressing data: incorrect header check > > > > whereas: > > > > >>> zlib.decompress(zlib.compress(b"foo")) > > b'foo' > > > > Unfortunately compress() doesn't accept the flags you seem to require. > > However, reading around a bit in the zlib docs turns up the compressobj > > which does. So > > > > >>> def mycompress(data): > > obj = zlib.compressobj(wbits=16 + zlib.MAX_WBITS) > > result = obj.compress(data) > > result += obj.flush() > > return result > > > > >>> zlib.decompress(mycompress(b"foo"), 16 + zlib.MAX_WBITS) > > b'foo' > > Thanks. Turns out I don't need this after all. Well I did need this after all and this works perfectly. Thanks so much! -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a conference in the US that is similar to EuroPython?
On Mon, Jul 19, 2021 at 10:01 AM Schachner, Joseph wrote: > > I am not going to fly to Europe for a Python conference. But, would consider > going if in the U.S.A. Especially if drivable ... NYC area would be ideal. > > I ask because I have seen ads for EuroPython over several years, and I don't > remember seeing similar ads for something similar in the U.S.A. https://pycon.org/ -- https://mail.python.org/mailman/listinfo/python-list
SQLALchemy: update with in clause from kwargs
I am trying to write a function that takes kwargs as a param and generates an update statement where the rows to be updated are specified in an in clause. Something like this: def update_by_in(self, **kwargs): filter_group = [] for col in kwargs['query_params']: # obviously this line does not work as col is a string, but this is the intent filter_group.append(col.in_(tuple(kwargs['query_params'][col]))) self._session.query(self.model_class).filter(*filter_group).update(kwargs['values']) self.update_by_in( **{'query_params': {'companyCode': ['A', 'B', 'C']}, 'values': {'portfolioName': 'test'}} ) Is there a way to do this? I think I need to use setattr in building up the filter_group list, but I'm not quite sure how to do it. -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLALchemy: update with in clause from kwargs
On Tue, Aug 3, 2021 at 7:26 PM dn via Python-list wrote: > > On 04/08/2021 13.08, Larry Martell wrote: > > I am trying to write a function that takes kwargs as a param and > > generates an update statement where the rows to be updated are > > specified in an in clause. > > > > Something like this: > > > > def update_by_in(self, **kwargs): > > filter_group = [] > > for col in kwargs['query_params']: > > # obviously this line does not work as col is a string, > > but this is the intent > > filter_group.append(col.in_(tuple(kwargs['query_params'][col]))) > > > > > > self._session.query(self.model_class).filter(*filter_group).update(kwargs['values']) > > > > self.update_by_in( > > **{'query_params': {'companyCode': ['A', 'B', 'C']}, > > 'values': {'portfolioName': 'test'}} > > ) > > > > Is there a way to do this? I think I need to use setattr in building > > up the filter_group list, but I'm not quite sure how to do it. > > > When feeling bamboozled by a problem, particularly when using > sophisticated tools such as SQLAlchemy, the trick is often to simplify > the problem. > > Step 1 (using the sample data provided) > Write the query on paper - and as constant-values. > > Step 2 > Compare the two input dicts with that requirement. > > Step 3 > Work-out the transformation(s) required... > > > One complexity is that the parameter to update_by_in() is formed by > joining two dicts. However, the function later tries to treat them in > distinct fashions. Why the join/why not two parameters? > > companyCode = ['A', 'B', 'C'] > values = {'portfolioName': 'test'} > > leading to: > > self.update_by_in( companyCode, values ) > > and: > > def update_by_in(self, company_code, portfolio_type ): > > > > As to the core of the question-asked, I'm a little confused (which may > be my fuzzy head). Do you want the update(s) - portrayed as a list - > like this: > > [('A', 'test'), ('B', 'test'), ('C', 'test')] > > like this: > > [('A', 'portfolioName'), ('B', None), ('C', None)] > > or only: > > [('A', 'portfolioName')] > > > You will find a friend in the itertools (PSL) library: > > import itertools as it > > list( it.product( companyCode, values.values() ) ) > [('A', 'test'), ('B', 'test'), ('C', 'test')] > > list( it.zip_longest( companyCode, values.values() ) ) > [('A', 'test'), ('B', None), ('C', None)] > > list( zip( companyCode, values ) ) > [('A', 'portfolioName')] > > > Now, have we simplified things to the point of being able to more-easily > code the update and filter? I appreciate the reply, but it does not address my issue, which was how to get at the column object. Turned out that was simple enough: for col in kwargs['query_params']: attr = getattr(self.model_class, col) filter_group.append(attr.in_(tuple(kwargs['query_params'][col]))) Unfortunately that is causing something to change the query_params, as filter group ends up like: print(type(filter_group[0])) print(filter_group[0]) dbo."Portfolio"."companyCode" IN (:companyCode_1, :companyCode_2, :companyCode_3) Which then fails with: sqlalchemy.orm.evaluator.UnevaluatableError: Cannot evaluate clauselist with operator This has now become more of a sqlalchemy question than a python one. -- https://mail.python.org/mailman/listinfo/python-list
All permutations from 2 lists
If I have 2 lists, e.g.: os = ["Linux","Windows"] region = ["us-east-1", "us-east-2"] How can I get a list of tuples with all possible permutations? So for this example I'd want: [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", "us-east-1"), "Windows", "us-east-2')] The lists can be different lengths or can be 0 length. Tried a few different things with itertools but have not got just what I need. TIA! -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Tue, Mar 1, 2022 at 7:21 PM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-03-01 at 19:12:10 -0500, > Larry Martell wrote: > > > If I have 2 lists, e.g.: > > > > os = ["Linux","Windows"] > > region = ["us-east-1", "us-east-2"] > > > > How can I get a list of tuples with all possible permutations? > > > > So for this example I'd want: > > > > [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", > > "us-east-1"), "Windows", "us-east-2')] > > > > The lists can be different lengths or can be 0 length. Tried a few > > different things with itertools but have not got just what I need. > > [(o, r) for o in os for r in region] This does not work if region = []. I wrote in my question that either list could be empty. -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Tue, Mar 1, 2022 at 7:32 PM Rob Cliffe wrote: > > I would not use `os` as an identifier, as it is the name of an important > built-in module. This is part of a much larger data structure, I created a simplified example. It is not actually called os. > I think itertools.product is what you need. > Example program: > > import itertools > opsys = ["Linux","Windows"] > region = ["us-east-1", "us-east-2"] > print(list(itertools.product(opsys, region))) This does not work if region = []. I wrote in question that either list could be empty. > Output: > > [('Linux', 'us-east-1'), ('Linux', 'us-east-2'), ('Windows', > 'us-east-1'), ('Windows', 'us-east-2')] > > itertools.product returns an iterator (or iterable, I'm not sure of the > correct technical term). > If you only want to use the result once you can write e.g. > > for ops, reg in itertools.product(opsys, region): > etc. > > If you need it more than once, you can convert it to a list (or tuple), > as above. > Best wishes > Rob Cliffe > > On 02/03/2022 00:12, Larry Martell wrote: > > If I have 2 lists, e.g.: > > > > os = ["Linux","Windows"] > > region = ["us-east-1", "us-east-2"] > > > > How can I get a list of tuples with all possible permutations? > > > > So for this example I'd want: > > > > [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", > > "us-east-1"), "Windows", "us-east-2')] > > > > The lists can be different lengths or can be 0 length. Tried a few > > different things with itertools but have not got just what I need. > > > > TIA! > -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon wrote: > > > Op 2/03/2022 om 14:27 schreef Larry Martell: > > On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com> wrote: > >> On 2022-03-01 at 19:12:10 -0500, > >> Larry Martell wrote: > >> > >>> If I have 2 lists, e.g.: > >>> > >>> os = ["Linux","Windows"] > >>> region = ["us-east-1", "us-east-2"] > >>> > >>> How can I get a list of tuples with all possible permutations? > >>> > >>> So for this example I'd want: > >>> > >>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", > >>> "us-east-1"), "Windows", "us-east-2')] > >>> > >>> The lists can be different lengths or can be 0 length. Tried a few > >>> different things with itertools but have not got just what I need. > >> [(o, r) for o in os for r in region] > > This does not work if region = []. I wrote in my question that either > > list could be empty. > > What do you mean it doesn't work? The result seems to be an empty list, > which IMO is a perfectly valid result. > > All possible permutations over two collections where one collection is > empty, should IMO give you an empty collection. If one list is empty I want just the other list. What I am doing is building a list to pass to a mongodb query. If region is empty then I want to query for just the items in the os list. I guess I can test for the lists being empty, but I'd like a solution that handles that as down the road there could be more than just 2 lists. -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 8:54 AM Joel Goldstick wrote: > > On Wed, Mar 2, 2022 at 8:46 AM Larry Martell wrote: > > > > On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon wrote: > > > > > > > > > Op 2/03/2022 om 14:27 schreef Larry Martell: > > > > On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com> > > > > wrote: > > > >> On 2022-03-01 at 19:12:10 -0500, > > > >> Larry Martell wrote: > > > >> > > > >>> If I have 2 lists, e.g.: > > > >>> > > > >>> os = ["Linux","Windows"] > > > >>> region = ["us-east-1", "us-east-2"] > > > >>> > > > >>> How can I get a list of tuples with all possible permutations? > > > >>> > > > >>> So for this example I'd want: > > > >>> > > > >>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", > > > >>> "us-east-1"), "Windows", "us-east-2')] > > > >>> > > > >>> The lists can be different lengths or can be 0 length. Tried a few > > > >>> different things with itertools but have not got just what I need. > > > >> [(o, r) for o in os for r in region] > > > > This does not work if region = []. I wrote in my question that either > > > > list could be empty. > > > > > > What do you mean it doesn't work? The result seems to be an empty list, > > > which IMO is a perfectly valid result. > > > > > > All possible permutations over two collections where one collection is > > > empty, should IMO give you an empty collection. > > > > If one list is empty I want just the other list. What I am doing is > > building a list to pass to a mongodb query. If region is empty then I > > want to query for just the items in the os list. I guess I can test > > for the lists being empty, but I'd like a solution that handles that > > as down the road there could be more than just 2 lists. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Does this help you out: > > >>> [(o,r) for o in opsys for r in region or "x"] > [('Linux', 'x'), ('Window', 'x')] That doesn't work if opsys = [] - either list could be empty. -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 9:10 AM Antoon Pardon wrote: > > Op 2/03/2022 om 14:44 schreef Larry Martell: > > On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon wrote: > >> > >> Op 2/03/2022 om 14:27 schreef Larry Martell: > >>> On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com> > >>> wrote: > >>>> On 2022-03-01 at 19:12:10 -0500, > >>>> Larry Martell wrote: > >>>> > >>>>> If I have 2 lists, e.g.: > >>>>> > >>>>> os = ["Linux","Windows"] > >>>>> region = ["us-east-1", "us-east-2"] > >>>>> > >>>>> How can I get a list of tuples with all possible permutations? > >>>>> > >>>>> So for this example I'd want: > >>>>> > >>>>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", > >>>>> "us-east-1"), "Windows", "us-east-2')] > >>>>> > >>>>> The lists can be different lengths or can be 0 length. Tried a few > >>>>> different things with itertools but have not got just what I need. > >>>> [(o, r) for o in os for r in region] > >>> This does not work if region = []. I wrote in my question that either > >>> list could be empty. > >> What do you mean it doesn't work? The result seems to be an empty list, > >> which IMO is a perfectly valid result. > >> > >> All possible permutations over two collections where one collection is > >> empty, should IMO give you an empty collection. > > If one list is empty I want just the other list. What I am doing is > > building a list to pass to a mongodb query. If region is empty then I > > want to query for just the items in the os list. I guess I can test > > for the lists being empty, but I'd like a solution that handles that > > as down the road there could be more than just 2 lists. > > How about the following: Keep a list of your lists you want to permute over. > Like the following: > > permutation_elements = [["Linux","Windows"],["us-east-1", "us-east-2"]] > > permutation = itertools.product(*permutation_elements) > > If you don't include the empty list, you will get more or less what you > seem to want. But I need to deal with that case. -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 9:37 AM Antoon Pardon wrote: > > > > Op 2/03/2022 om 15:29 schreef Larry Martell: > > On Wed, Mar 2, 2022 at 9:10 AM Antoon Pardon wrote: > >> Op 2/03/2022 om 14:44 schreef Larry Martell: > >>> On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon > >>> wrote: > >>>> Op 2/03/2022 om 14:27 schreef Larry Martell: > >>>>> On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com> > >>>>> wrote: > >>>>>> On 2022-03-01 at 19:12:10 -0500, > >>>>>> Larry Martellwrote: > >>>>>> > >>>>>>> If I have 2 lists, e.g.: > >>>>>>> > >>>>>>> os = ["Linux","Windows"] > >>>>>>> region = ["us-east-1", "us-east-2"] > >>>>>>> > >>>>>>> How can I get a list of tuples with all possible permutations? > >>>>>>> > >>>>>>> So for this example I'd want: > >>>>>>> > >>>>>>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows", > >>>>>>> "us-east-1"), "Windows", "us-east-2')] > >>>>>>> > >>>>>>> The lists can be different lengths or can be 0 length. Tried a few > >>>>>>> different things with itertools but have not got just what I need. > >>>>>> [(o, r) for o in os for r in region] > >>>>> This does not work if region = []. I wrote in my question that either > >>>>> list could be empty. > >>>> What do you mean it doesn't work? The result seems to be an empty list, > >>>> which IMO is a perfectly valid result. > >>>> > >>>> All possible permutations over two collections where one collection is > >>>> empty, should IMO give you an empty collection. > >>> If one list is empty I want just the other list. What I am doing is > >>> building a list to pass to a mongodb query. If region is empty then I > >>> want to query for just the items in the os list. I guess I can test > >>> for the lists being empty, but I'd like a solution that handles that > >>> as down the road there could be more than just 2 lists. > >> How about the following: Keep a list of your lists you want to permute > >> over. > >> Like the following: > >> > >> permutation_elements = [["Linux","Windows"],["us-east-1", "us-east-2"]] > >> > >> permutation = itertools.product(*permutation_elements) > >> > >> If you don't include the empty list, you will get more or less what you > >> seem to want. > > But I need to deal with that case. > > What does that mean? How does using the above method to produce the > permutations > you want, prevent you from dealing with an empty list however you want when > you > encounter them? Just don't add them to the permutation_elements. I need to know what items are in which position. If sometimes the regions are in one index and sometimes in another will not work for me. -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 10:26 AM Antoon Pardon wrote: > > > > Op 2/03/2022 om 15:58 schreef Larry Martell: > > On Wed, Mar 2, 2022 at 9:37 AM Antoon Pardon wrote: > >> > >>>>> If one list is empty I want just the other list. What I am doing is > >>>>> building a list to pass to a mongodb query. If region is empty then I > >>>>> want to query for just the items in the os list. I guess I can test > >>>>> for the lists being empty, but I'd like a solution that handles that > >>>>> as down the road there could be more than just 2 lists. > >>>> How about the following: Keep a list of your lists you want to permute > >>>> over. > >>>> Like the following: > >>>> > >>>> permutation_elements = [["Linux","Windows"],["us-east-1", "us-east-2"]] > >>>> > >>>> permutation = itertools.product(*permutation_elements) > >>>> > >>>> If you don't include the empty list, you will get more or less what you > >>>> seem to want. > >>> But I need to deal with that case. > >> What does that mean? How does using the above method to produce the > >> permutations > >> you want, prevent you from dealing with an empty list however you want > >> when you > >> encounter them? Just don't add them to the permutation_elements. > > I need to know what items are in which position. If sometimes the > > regions are in one index and sometimes in another will not work for > > me. > > I am starting to suspect you didn't think this through. What you are telling > here > contradicts what you told earlier that if either list was empty, you just > wanted > the other list. Because then you wouldn't know what items were in that list. > > The only solution I can see now is that if a list is empty, you either add > [None] or > [""] to the permutation_elements (whatever suits you better) and then use > itertools.product I found a way to pass this directly into the query: def query_lfixer(query): for k, v in query.items(): if type(v)==list: query[k] = {"$in": v} return query self._db_conn[collection_name].find(query_lfixer(query)) -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 5:00 PM Cameron Simpson wrote: > > On 02Mar2022 08:29, Larry Martell wrote: > >On Tue, Mar 1, 2022 at 7:32 PM Rob Cliffe wrote: > >> I think itertools.product is what you need. > >> Example program: > >> > >> import itertools > >> opsys = ["Linux","Windows"] > >> region = ["us-east-1", "us-east-2"] > >> print(list(itertools.product(opsys, region))) > > > >This does not work if region = []. I wrote in question that either > >list could be empty. > > What do you want to get if a list is empty? You haven't said. My > personal expectation would be an empty result. > > Alternatively, if you expect an empty list to imply some single default > the the experession: > > the_list or (the_default,) > > might be of use. I've solved the issue. -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 5:31 PM Joel Goldstick wrote: > > On Wed, Mar 2, 2022 at 5:07 PM Larry Martell wrote: > > > > On Wed, Mar 2, 2022 at 5:00 PM Cameron Simpson wrote: > > > > > > On 02Mar2022 08:29, Larry Martell wrote: > > > >On Tue, Mar 1, 2022 at 7:32 PM Rob Cliffe > > > >wrote: > > > >> I think itertools.product is what you need. > > > >> Example program: > > > >> > > > >> import itertools > > > >> opsys = ["Linux","Windows"] > > > >> region = ["us-east-1", "us-east-2"] > > > >> print(list(itertools.product(opsys, region))) > > > > > > > >This does not work if region = []. I wrote in question that either > > > >list could be empty. > > > > > > What do you want to get if a list is empty? You haven't said. My > > > personal expectation would be an empty result. > > > > > > Alternatively, if you expect an empty list to imply some single default > > > the the experession: > > > > > > the_list or (the_default,) > > > > > > might be of use. > > > > I've solved the issue. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Would you be so kind as to show the results of your solution? I posted it at 10:49am Eastern time. -- https://mail.python.org/mailman/listinfo/python-list
Re: All permutations from 2 lists
On Wed, Mar 2, 2022 at 9:42 PM Avi Gross via Python-list wrote: > > Larry, > > i waited patiently to see what others will write and perhaps see if you > explain better what you need. You seem to gleefully swat down anything > offered. So I am not tempted to engage. But then you gave in to the temptation. > And it is hard to guess as it is not clear what you will do with this. In the interests of presenting a minimal example I clearly oversimplified. This is my use case: I get a dict from an outside source. The dict contains key/value pairs that I need to use to query a mongodb database. When the values in the dict are all scalar I can pass the dict directly into the query, e.g.: self._db_conn[collection_name].find(query). But if any of the values are lists that does not work. I need to query with something like the cross product of all the lists. It's not a true product since if a list is empty it means no filtering on that field, not no filtering on all the fields. Originally I did not know I could generate a single query that did that. So I was trying to come up with a way to generate a list of all the permutations and was going to issue a query for each individually. Clearly that would become very inefficient if the lists were long or there were a lot of lists. I then found that I could specify a list with the "$in" clause, hence my solution. > def query_lfixer(query): > for k, v in query.items(): > if type(v)==list: > query[k] = {"$in": v} > return query > > self._db_conn[collection_name].find(query_lfixer(query)) > > > So why did so many of us bother? Indeed - so why did you bother? -- https://mail.python.org/mailman/listinfo/python-list
calling a function asynchronously
I have a django app, and for a certain request I need to kick off a long running task. I want to do this asynchronously and immediately return a response. I tried using subprocess.Process() but the forked process does not have a django database connection. I then tried posting a request using ajax but that does not have a django session so it's not authorized. Tried using asyncio but I am finding the caller of the async function does not return until the async function returns - maybe I am doing something wrong, as it does appear to be actually asynchronous. I tried this test: import asyncio import time async def long(): for i in range(100): time.sleep(10) asyncio.run(long()) print('after asyncio.run') The final print does not come out until after long() completes. Is there any way to do this? -- https://mail.python.org/mailman/listinfo/python-list
Re: calling a function asynchronously
On Wed, Mar 30, 2022 at 2:40 PM Kirill Ratkin via Python-list wrote: > > Hi again, > > I changed a bit your example and it works as you expected I hope. > > import asyncio > > > async def long(): > for i in range(100): > await asyncio.sleep(10) > print("long is done") > > > loop = asyncio.get_event_loop() > > task = loop.create_task(long()) > print('after asyncio.run') > loop.run_until_complete(asyncio.gather(task)) > > > But how I wrote before ... if you are in big Django project just look at > existent django libraries for long task running. One of it I sent you. > There is 'celery' as well. > > It's more pragmatic way ... Appreciate the reply. I did not know about django-background-tasks - thanks. I've been trying to make use of that. I do not get the errors I was getting before but it does not appear that my long running task is running at all. Still debugging. But concerting asyncio - doesn't run_until_complete block until long() completes? > > 30.03.2022 19:10, Larry Martell пишет: > > import asyncio > > import time > > > > async def long(): > > for i in range(100): > > time.sleep(10) > > > > asyncio.run(long()) > > print('after asyncio.run') > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: type lookuperror
On Thu, Aug 18, 2016 at 10:02 AM, Gene Heskett wrote: > On Thursday 18 August 2016 07:28:06 Chris Angelico wrote: > >> On Thu, Aug 18, 2016 at 7:55 PM, meInvent bbird > wrote: >> > actually i would like to remove try except code in all function >> > >> > and i feel that try except code for a large block code can not >> > show which function name , which line number error, >> > if use try except for specified code block to show where it has >> > error it will have many ugly try except code and need many human >> > force to craft the code, i hope that code write once for program to >> > program itself in future. >> > >> > actually this method i ask is not good enough since it will need >> > to add many function wrapper. >> >> You can't get a program to program itself. That's called the >> Singularity [1], and depending on your point of view, it's either >> still in the future, or fundamentally impossible. In any case, >> computers today cannot program themselves. > > That is a pretty broad statement to make, considering I have actually > done it. On an RCA 1802 based (Cosmac Super Elf) computer. Every byte of > static ram memory in those days (1978) was precious, (4k board kit was > $250) so rather than having 30 nearly identical copies of a subroutine > each doing a similar job but with different data, I actually overwrote 3 > or 4 bytes of a single subroutine to change what it did according to > where it was in the main loop. So when it was done with that pass, it > put the original bytes back. Controlling a videotape machine at a tv > station in northern kalipornia, it was dead stable, running from power > failure to power failure. And, I checked about 15 years later, and it > was still in 10+ times a day use. If memory was that precious today, it > would still be a valid method to shrink a complex program. Freshman year of college, 1977, final exam for a Fortran class. One of the questions was to write some program but only use some specified small amount of memory. I do not think anyone in the class was able to do it. The only way to do it was to write self modifying code, something that we had never covered in class. -- https://mail.python.org/mailman/listinfo/python-list
saving octet-stream png file
I have some python code (part of a django app) that processes a request that contains a png file. The request is send with content_type = 'application/octet-stream' In the python code I want to write this data to a file and still have it still be a valid png file. The data I get looks like this: u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd ..' If I try and write that to a file it fails with a UnicodeEncodeError. If I write it with encode('utf8') it writes the file, but then it's no longer a valid png file. Anyone know how I can do this? -- https://mail.python.org/mailman/listinfo/python-list
Re: saving octet-stream png file
On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico wrote: > On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell > wrote: >> I have some python code (part of a django app) that processes a >> request that contains a png file. The request is send with >> content_type = 'application/octet-stream' >> >> In the python code I want to write this data to a file and still have >> it still be a valid png file. >> >> The data I get looks like this: >> >> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd >> ..' >> >> If I try and write that to a file it fails with a UnicodeEncodeError. >> If I write it with encode('utf8') it writes the file, but then it's no >> longer a valid png file. >> >> Anyone know how I can do this? > > At that point, you've already lost information. Each U+FFFD (shown as > "\ufffd" above) is a marker saying "a byte here was not valid UTF-8" > (or whatever was being used). Something somewhere took the .png file's > bytes and tried to interpret them as text, which they're not. > > What sent you that data? How did you receive it? The request is sent by a client app written in C++ with Qt. It's received by a django based server. I am trying to port a falcon server to django. The falcon server code did this: form = cgi.FieldStorage(fp=req.stream, environ=req.env) and then wrote the png like this: fd.write(form[key].file.read()) Whereas in the django server I am doing: fd.write(request.POST[key]) I've never used the cgi module. I guess I can try that. I've written a lot with django but never had to receive a PNG file. -- https://mail.python.org/mailman/listinfo/python-list
Re: saving octet-stream png file
On Fri, Aug 19, 2016 at 3:00 PM, Larry Martell wrote: > On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico wrote: >> On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell >> wrote: >>> I have some python code (part of a django app) that processes a >>> request that contains a png file. The request is send with >>> content_type = 'application/octet-stream' >>> >>> In the python code I want to write this data to a file and still have >>> it still be a valid png file. >>> >>> The data I get looks like this: >>> >>> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd >>> ..' >>> >>> If I try and write that to a file it fails with a UnicodeEncodeError. >>> If I write it with encode('utf8') it writes the file, but then it's no >>> longer a valid png file. >>> >>> Anyone know how I can do this? >> >> At that point, you've already lost information. Each U+FFFD (shown as >> "\ufffd" above) is a marker saying "a byte here was not valid UTF-8" >> (or whatever was being used). Something somewhere took the .png file's >> bytes and tried to interpret them as text, which they're not. >> >> What sent you that data? How did you receive it? > > The request is sent by a client app written in C++ with Qt. It's > received by a django based server. I am trying to port a falcon server > to django. The falcon server code did this: > > form = cgi.FieldStorage(fp=req.stream, environ=req.env) > > and then wrote the png like this: > > fd.write(form[key].file.read()) > > Whereas in the django server I am doing: > > fd.write(request.POST[key]) > > I've never used the cgi module. I guess I can try that. I've written a > lot with django but never had to receive a PNG file. No joy using cgi.FieldStorage. The request I get (of type django.core.handlers.wsgi.WSGIRequest) does not have a stream method. I'm sure there's some way to do this, but I have not come up with anything googling. Going to try the django list. -- https://mail.python.org/mailman/listinfo/python-list
Re: saving octet-stream png file
On Sun, Aug 21, 2016 at 5:24 PM, Jon Ribbens wrote: > On 2016-08-19, Larry Martell wrote: >> fd.write(request.POST[key]) > > You could try: > > request.encoding = "iso-8859-1" > fd.write(request.POST[key].encode("iso-8859-1")) > > It's hacky and nasty and there might be a better "official" method > but I think it should work. For some reason that messes up the request structure: (Pdb) type(request.POST[key]) (Pdb) request.encoding = "iso-8859-1" (Pdb) type(request.POST[key]) *** MultiValueDictKeyError: "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'" -- https://mail.python.org/mailman/listinfo/python-list
Re: saving octet-stream png file
On Fri, Aug 19, 2016 at 4:24 PM, Chris Kaynor wrote: > On Fri, Aug 19, 2016 at 12:00 PM, Larry Martell > wrote: > >> On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico wrote: >> > On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell >> wrote: >> >> I have some python code (part of a django app) that processes a >> >> request that contains a png file. The request is send with >> >> content_type = 'application/octet-stream' >> >> >> >> In the python code I want to write this data to a file and still have >> >> it still be a valid png file. >> >> >> >> The data I get looks like this: >> >> >> >> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\ >> x00\x00\x01\ufffd >> >> ..' >> >> >> >> If I try and write that to a file it fails with a UnicodeEncodeError. >> >> If I write it with encode('utf8') it writes the file, but then it's no >> >> longer a valid png file. >> >> >> >> Anyone know how I can do this? >> > >> > At that point, you've already lost information. Each U+FFFD (shown as >> > "\ufffd" above) is a marker saying "a byte here was not valid UTF-8" >> > (or whatever was being used). Something somewhere took the .png file's >> > bytes and tried to interpret them as text, which they're not. >> > >> > What sent you that data? How did you receive it? >> >> The request is sent by a client app written in C++ with Qt. It's >> received by a django based server. I am trying to port a falcon server >> to django. The falcon server code did this: >> >> form = cgi.FieldStorage(fp=req.stream, environ=req.env) >> >> and then wrote the png like this: >> >> fd.write(form[key].file.read()) >> >> Whereas in the django server I am doing: >> >> fd.write(request.POST[key]) >> >> I've never used the cgi module. I guess I can try that. I've written a >> lot with django but never had to receive a PNG file. >> >> > I don't know Django, however a quick search makes it seem like you might > need to use request.FILES[key] (1) rather than request.POST[key]. You may > also be able to use request.POST if you set request.encoding first (2). If > both of those fail, you may need to use request.body and parse the HTTP > form data manually, though I'd imagine there is an easier way. > > [1] > https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.FILES > > [2] > https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.encoding Thanks for the reply. When I get the request, request.FILES is empty. Yet the content type is multipart/form-data and the method is POST: (Pdb) print request.META['CONTENT_TYPE'] multipart/form-data; boundary="boundary_.oOo._NzEwNjIzMTM4MTI4NjUxOTM5OQ==MTY2NjE4MDk5Nw==" (Pdb) print request.META['REQUEST_METHOD'] POST (Pdb) print request.FILES Tried setting request.encoding, but that messes up the request structure: (Pdb) type(request.POST[key]) (Pdb) request.encoding = "iso-8859-1" (Pdb) type(request.POST[key]) *** MultiValueDictKeyError: "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'" -- https://mail.python.org/mailman/listinfo/python-list
Re: saving octet-stream png file
On Mon, Aug 22, 2016 at 10:36 AM, Larry Martell wrote: > On Fri, Aug 19, 2016 at 4:24 PM, Chris Kaynor > wrote: >> On Fri, Aug 19, 2016 at 12:00 PM, Larry Martell >> wrote: >> >>> On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico wrote: >>> > On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell >>> wrote: >>> >> I have some python code (part of a django app) that processes a >>> >> request that contains a png file. The request is send with >>> >> content_type = 'application/octet-stream' >>> >> >>> >> In the python code I want to write this data to a file and still have >>> >> it still be a valid png file. >>> >> >>> >> The data I get looks like this: >>> >> >>> >> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\ >>> x00\x00\x01\ufffd >>> >> ..' >>> >> >>> >> If I try and write that to a file it fails with a UnicodeEncodeError. >>> >> If I write it with encode('utf8') it writes the file, but then it's no >>> >> longer a valid png file. >>> >> >>> >> Anyone know how I can do this? >>> > >>> > At that point, you've already lost information. Each U+FFFD (shown as >>> > "\ufffd" above) is a marker saying "a byte here was not valid UTF-8" >>> > (or whatever was being used). Something somewhere took the .png file's >>> > bytes and tried to interpret them as text, which they're not. >>> > >>> > What sent you that data? How did you receive it? >>> >>> The request is sent by a client app written in C++ with Qt. It's >>> received by a django based server. I am trying to port a falcon server >>> to django. The falcon server code did this: >>> >>> form = cgi.FieldStorage(fp=req.stream, environ=req.env) >>> >>> and then wrote the png like this: >>> >>> fd.write(form[key].file.read()) >>> >>> Whereas in the django server I am doing: >>> >>> fd.write(request.POST[key]) >>> >>> I've never used the cgi module. I guess I can try that. I've written a >>> lot with django but never had to receive a PNG file. >>> >>> >> I don't know Django, however a quick search makes it seem like you might >> need to use request.FILES[key] (1) rather than request.POST[key]. You may >> also be able to use request.POST if you set request.encoding first (2). If >> both of those fail, you may need to use request.body and parse the HTTP >> form data manually, though I'd imagine there is an easier way. >> >> [1] >> https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.FILES >> >> [2] >> https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.encoding > > Thanks for the reply. When I get the request, request.FILES is empty. > Yet the content type is multipart/form-data and the method is POST: > > (Pdb) print request.META['CONTENT_TYPE'] > multipart/form-data; > boundary="boundary_.oOo._NzEwNjIzMTM4MTI4NjUxOTM5OQ==MTY2NjE4MDk5Nw==" > > (Pdb) print request.META['REQUEST_METHOD'] > POST > > (Pdb) print request.FILES > > > Tried setting request.encoding, but that messes up the request structure: > > (Pdb) type(request.POST[key]) > > (Pdb) request.encoding = "iso-8859-1" > (Pdb) type(request.POST[key]) > *** MultiValueDictKeyError: > "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'" Thanks to everyone for they replied. I solved this by changing the client to set the file and filename fields each part of the multipart and then I was able it iterate through request.FILES and successfully write the files as PNG. -- https://mail.python.org/mailman/listinfo/python-list
Re: saving octet-stream png file
On Fri, Aug 19, 2016 at 4:51 PM, Lawrence D’Oliveiro wrote: > On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote: >> >> An 'octet' is a byte of 8 bits. > > Is there any other size of byte? Many, many years ago, probably c. 1982 my Dad came into my house and saw a Byte Magazine laying on the coffee table. He asked "What is a byte?" I replied "Half a word." He then asked "What is the other half of the word?" I said "That is also a byte." He thought for a moment, then said "So the full word is 'byte byte'?" -- https://mail.python.org/mailman/listinfo/python-list
Re: DED processing
On Mon, Aug 22, 2016 at 1:52 PM, Gary Sublett wrote: > I have to go out for a while, so for DED processing two options from > my end: > > 1. Process as you all have been in the past for now. If you all do > this, the records that have not been mailed prior to the latest list > are contained in a MailManage Job name DED_master. If you chose to > process as in the past, these records should be exported to a > spreadsheet and added to whatever new file you have for today. > > 2. I can come in tomorrow morning at about 9:00 and walk Greg thru > the way I process the DED job. > > Let me know. I think you should let Greg know. What if you get hit by a bus, or win the lottery? -- https://mail.python.org/mailman/listinfo/python-list
Re: saving octet-stream png file
On Mon, Aug 22, 2016 at 1:25 PM, Jon Ribbens wrote: > On 2016-08-22, Larry Martell wrote: >> On Sun, Aug 21, 2016 at 5:24 PM, Jon Ribbens >> wrote: >>> On 2016-08-19, Larry Martell wrote: >>>> fd.write(request.POST[key]) >>> >>> You could try: >>> >>> request.encoding = "iso-8859-1" >>> fd.write(request.POST[key].encode("iso-8859-1")) >>> >>> It's hacky and nasty and there might be a better "official" method >>> but I think it should work. >> >> For some reason that messes up the request structure: >> >> (Pdb) type(request.POST[key]) >> >> (Pdb) request.encoding = "iso-8859-1" >> (Pdb) type(request.POST[key]) >> *** MultiValueDictKeyError: >> "u'right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png'" > > Sounds like you should be filing a bug report with Django. Turns out that is expected behavior -- request.encoding clears existing GET/POST data. Not sure how it's useful to set that then. -- https://mail.python.org/mailman/listinfo/python-list
Re: Is duck-typing misnamed?
On Fri, Aug 26, 2016 at 7:58 PM, ROGER GRAYDON CHRISTMAN wrote: > "If it walks like a duck, quacks like a duck,... " > > so there is indeed precedence for this so-called 'duck typing' > > > but wouldn't it be more Pythonic to call this 'witch typing'? > > "How do you know she is a witch?" > > "She looks like one." > > etc. > > > I do grant that ultimately, the duck does come into play, since the witch > weighs the same as a duck. Great idea, I love it. Now go and change your armor. -- https://mail.python.org/mailman/listinfo/python-list
Re: while loop
On Tue, Oct 11, 2016 at 1:58 PM, wrote: > > n=6 > x=1 > while x<=n: > print "*"*x > x+=1 > while n>=x: > n=n-1 > print "*"* n > > > Only first loop is executing not the second one? Because after the first loop n < x -- https://mail.python.org/mailman/listinfo/python-list
Re: Can somebody tell me what's wrong wrong with my code? I don't understand
On Mon, Nov 21, 2016 at 10:10 PM, wrote: > Hi! This is my first post! I'm having trouble understanding my code. I get > "SyntaxError:invalid syntax" on line 49. I'm trying to code a simple > text-based rpg on repl.it. Thank you for reading. > > > > print("Welcome to Gladiator Game! Choose your character race, class, and > starting equipment!") > > print('') > > print("Race selection: ") > > print('') > > print("(1) Orcs. Known for their very wide, robust physiques. They are the > strongest of all the races in Polaris.") > > print('') > > print("(2) Elves. Thin and wiry. They are known for their amazing agility and > hand-eye coordiation. They originate from the desert island of Angolia.") > > print('') > > print("(3) Silverbacks. A hairy, ape-like race from Nothern Polaris. Their > metal fur provides them with much needed protection.") > > print('') > > print("(4) Pomongos. An amphibian race believed to inhabit the wet jungles of > Central Polaris. Legends say they have highly corrosive spit...") > > print('') > > raceNum=int(input("Select your character's race by entering the corresponding > number. Then press enter: ")) > > print('') > > while raceNum<1 or raceNum>4: > raceNum=int(input('Invalid input. Try again: ')) > > print('') > > if raceNum==1: > print("You're an orc, eh? I won't be sayin' anything mean about you...") > print('') > classNum=int(input("What's your profession big fella?")) > > elif raceNum==2: > print("I never liked you elven folk...Let's get on with this.") > print('') > classNum=int(input("What's your profession ? Do ye even have one ?")) > > elif raceNum==3: > print("Nice fur. I don't see too many of your kind 'round here. Maybe > that's a good thing...") > print('') > classNum=int(input("What's your profession mate?") > > elif raceNum==4: #this line has an error for some reason > print("Your a 'Mongo eh? I thought you lads were extinct...Just keep your > tongue in ya mouth and we'll get along fine mate.") > classNum=int(input("What's your profession?")) Hint: look on line 47 -- https://mail.python.org/mailman/listinfo/python-list
dateutil timezone question
I have a datetime that looks like this: '2016-11-11T18:10:09-05:00' and when I pass it to dateutil.parser.parse I get back this: datetime.datetime(2016, 11, 11, 18, 10, 9, tzinfo=tzoffset(None, -18000)) And I have other datetimes like this: '2016-04-27T00:00:00', which went passed to dateutil.parser.parse of course does not return a datetime with the tzinfo. I need to compare these datetimes, and if I do that I get the dreaded "can't compare offset-naive and offset-aware datetimes" error. Is there a way I can get it back without the tzinfo, but instead with the offset applied to the date, so I can compare these 2? In other words I want it to return datetime.datetime(2016, 11, 11, 13, 10, 9) -- https://mail.python.org/mailman/listinfo/python-list
Re: dateutil timezone question
On Fri, Dec 23, 2016 at 2:18 PM, Chris Angelico wrote: > On Sat, Dec 24, 2016 at 3:30 AM, Larry Martell > wrote: >> I have a datetime that looks like this: '2016-11-11T18:10:09-05:00' >> and when I pass it to dateutil.parser.parse I get back this: >> >> datetime.datetime(2016, 11, 11, 18, 10, 9, tzinfo=tzoffset(None, -18000)) >> >> And I have other datetimes like this: '2016-04-27T00:00:00', which >> went passed to dateutil.parser.parse of course does not return a >> datetime with the tzinfo. >> >> I need to compare these datetimes, and if I do that I get the dreaded >> "can't compare offset-naive and offset-aware datetimes" error. > > Some of your timestamps have timezones and others don't. That's a > fundamental problem. Are you absolutely certain that the ones without > them are in UTC? If so, the easiest fix would be to slap a "Z" on them > before you parse, which would give you exclusively aware datetimes. What I ended up doing, which I think is somewhat kludgy is this: def add_tz(datestr): if datestr is None or len(datestr) < 6: return datestr if datestr[-6] == ':': return datestr+'-00:00' else: return datestr Then I pass all my dates through that before calling dateutil.parser.parse -- https://mail.python.org/mailman/listinfo/python-list
Re: dateutil timezone question
On Fri, Dec 23, 2016 at 2:27 PM, Skip Montanaro wrote: >> I need to compare these datetimes, and if I do that I get the dreaded >> "can't compare offset-naive and offset-aware datetimes" error. > > If you're sure the naive datetimes are UTC, this should work: > > import pytz > > dt = pytz.utc.localize(dateutil.parser.parse('2016-04-27T00:00:00')) > > You can then compare it with other tz-containing datetime objects. I did mess around with pytz a bit but I was getting a lot of exceptions - something related to the TZ already being set or something like that. I don't recall exactly, and I can't scroll back far enough to find it. -- https://mail.python.org/mailman/listinfo/python-list
sorting strings numerically while dealing with missing values
I have a list containing a list of strings that I want to sort numerically by one of the fields. I am doing this: sorted(rows, key=float(itemgetter(sortby))) Which works fine as long as all the sort keys convert to a float. Problem is that some are blank or None and those throw an exception. How can I handle that case and still sort? I'd want the blank or None fields to come out either at the beginning or end of the sorted list (not sure what the customer wants for this yet). -- https://mail.python.org/mailman/listinfo/python-list
Re: sorting strings numerically while dealing with missing values
On Wed, Dec 28, 2016 at 3:43 PM, Ian Kelly wrote: > On Wed, Dec 28, 2016 at 2:14 PM, Larry Martell > wrote: >> >> I have a list containing a list of strings that I want to sort >> numerically by one of the fields. I am doing this: >> >> sorted(rows, key=float(itemgetter(sortby))) > > I'm guessing that you left out a lambda here since the key argument > takes a function. > >> Which works fine as long as all the sort keys convert to a float. >> Problem is that some are blank or None and those throw an exception. >> How can I handle that case and still sort? I'd want the blank or None >> fields to come out either at the beginning or end of the sorted list >> (not sure what the customer wants for this yet). > > > def sort_key(sortby, none_first=False): > def key(row): > try: > value = float(row[sortby]) > except ValueError: > value = None > return ((value is None) != none_first, value) > return key > > sorted(rows, key=sort_key(4, none_first=True)) Thanks. I got this working using a function similar to this. -- https://mail.python.org/mailman/listinfo/python-list
Re: Clickable hyperlinks
On Mon, Jan 9, 2017 at 5:33 PM, Deborah Swanson wrote: > Ok, here is the crux of this thread's communication problem. I didn't > ask, or particularly care for all these lectures on the technology of > terminal emulators. I asked how to code Python to make clickable links. > > Since all of you are quite obviously passionate about terminal > emulators, I would suggest that you start your own thread. Except that > it would have nothing to do with Python, and would be OT for this list. > What you're doing instead is thread jacking, hijacking a thread to talk > about a different topic. And in every list I've ever been on, thread > jacking is considered to be very rude. And it's also confusing if the > two topics are similar, which is exactly what happened here. Once you start a thread and put it out in the ether, it takes on a life of its own, and cannot be controlled by anyone. That is true more on this list then any other of the 100's I've been on. And it's why I love it here. -- https://mail.python.org/mailman/listinfo/python-list
sorting a list of dicts by a computed field
I have a list of dicts and one item of the dict is a date in m/d/Y format. I want to sort by that. I tried this: sorted(data['trends'], key=lambda k: datetime.strptime(k['date_time'],'%m/%d/%Y')) But that fails with: Exception Type: AttributeError at /report/CDSEM/WaferAlignment/ajax/waChart.json Exception Value: 'module' object has no attribute 'strptime' How can I do this sort? -- https://mail.python.org/mailman/listinfo/python-list