Force virtualenv pip to be used
Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? $ virtualenv a && . "$_"/bin/activate && pip --version New python executable in /tmp/a/bin/python Installing setuptools, pip, wheel...done. pip 9.0.0 from /usr/local/lib/python2.7/dist-packages (python 2.7) $ /tmp/a/bin/pip --version pip 9.0.0 from /usr/local/lib/python2.7/dist-packages (python 2.7) $ /tmp/a/bin/python -c 'from pip import __file__; print __file__' /usr/local/lib/python2.7/dist-packages/pip/__init__.pyc PS: Running with regular Bash 4.3.46(1)-release in GNOME Terminal. When I activate the virtualenv this appears in my env output: VIRTUAL_ENV=/tmp/a PPS: Cross-posted [yesterday] http://stackoverflow.com/q/40438089 -- https://mail.python.org/mailman/listinfo/python-list
Re: Force virtualenv pip to be used
Alec Taylor wrote: > Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv > 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? > > $ virtualenv a && . "$_"/bin/activate && pip --version > New python executable in /tmp/a/bin/python > Installing setuptools, pip, wheel...done. > pip 9.0.0 from /usr/local/lib/python2.7/dist-packages (python 2.7) > $ /tmp/a/bin/pip --version > pip 9.0.0 from /usr/local/lib/python2.7/dist-packages (python 2.7) > $ /tmp/a/bin/python -c 'from pip import __file__; print __file__' > /usr/local/lib/python2.7/dist-packages/pip/__init__.pyc > > PS: Running with regular Bash 4.3.46(1)-release in GNOME Terminal. When I > activate the virtualenv this appears in my env output: VIRTUAL_ENV=/tmp/a > > PPS: Cross-posted [yesterday] http://stackoverflow.com/q/40438089 What's in your PYTHONPATH? $ export PYTHONPATH=/usr/lib/python2.7/dist-packages/ $ virtualenv a && . "$_"/bin/activate && pip --version New python executable in a/bin/python Installing setuptools, pip...done. pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7) (a)$ unset PYTHONPATH (a)$ pip --version pip 1.5.4 from /home/peter/a/local/lib/python2.7/site-packages (python 2.7) -- https://mail.python.org/mailman/listinfo/python-list
Re: Force virtualenv pip to be used
On Sun, Nov 6, 2016 at 9:17 PM, Alec Taylor wrote: > Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv > 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? > > $ virtualenv a && . "$_"/bin/activate && pip --version I'm pretty sure virtualenv (like venv, about which I'm certain) creates something that you have to 'source' into your shell, rather than running in the classic way: source env/bin/activate It needs to alter environment variables in your shell, which can't be done from a separate program. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: pip3 : command not found
On Sun, Nov 6, 2016 at 4:27 PM, Jon Ribbens wrote: >> 2) If Python notices that its executable comes from a venv, it uses it. > > Yes. My question is *how does it notice*? I could answer this question, but since you don't appear to be following the thread properly, I'll point out that it's already been said up above. Go read it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Force virtualenv pip to be used
Chris Angelico wrote: > On Sun, Nov 6, 2016 at 9:17 PM, Alec Taylor > wrote: >> Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv >> 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? >> >> $ virtualenv a && . "$_"/bin/activate && pip --version > > I'm pretty sure virtualenv (like venv, about which I'm certain) > creates something that you have to 'source' into your shell, rather > than running in the classic way: > > source env/bin/activate I think this is what the . "$_"/bin/activate part of Alec's command is supposed to do. Yes, that's a dot, not grit on Tim's screen ;) > It needs to alter environment variables in your shell, which can't be > done from a separate program. -- https://mail.python.org/mailman/listinfo/python-list
Re: Force virtualenv pip to be used
On Sunday, November 6, 2016 at 10:20:53 PM UTC+11, Peter Otten wrote: > Chris Angelico wrote: > > > On Sun, Nov 6, 2016 at 9:17 PM, Alec Taylor > > wrote: > >> Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv > >> 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? > >> > >> $ virtualenv a && . "$_"/bin/activate && pip --version > > > > I'm pretty sure virtualenv (like venv, about which I'm certain) > > creates something that you have to 'source' into your shell, rather > > than running in the classic way: > > > > source env/bin/activate > > I think this is what the > > . "$_"/bin/activate > > part of Alec's command is supposed to do. > > Yes, that's a dot, not grit on Tim's screen ;) > > > It needs to alter environment variables in your shell, which can't be > > done from a separate program. Hmm: $ echo $PYTHONPATH /usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/dist-packages $ pip --version pip 9.0.0 from /tmp/a/local/lib/python2.7/site-packages (python 2.7) So that worked. Shouldn't PYTHONPATH be set/upserted by the activation of the virtualenv? -- https://mail.python.org/mailman/listinfo/python-list
Regarding the parsing of await expression.
Hi, In the pep, https://www.python.org/dev/peps/pep-0492/#examples-of-await-expressions It is said, await await coro() is SyntaxError, instead, we should use await (await coro()) Why? because of await is not left-associative? also, for await -coro() , it should be written as, await (-coro()) I don't understand the point here. Why can't the parser figure out it indeed is await (-coro()) ? Is it due to the fact Python uses LL(1) or just because of current impl doesn't do that? Regards. -- https://mail.python.org/mailman/listinfo/python-list
passing a variable to cmd
Note the following code:
import subprocess
import shlex
domname = raw_input("Enter your domain name: ");
print "Your domain name is: ", domname
print "\n"
# cmd='dig @4.2.2.2 nbc.com ns +short'
cmd="dig @4.2.2.2 %s ns +short", % (domname)
proc=subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE)
out,err=proc.communicate()
print(out)
The line that is commented out works fine. However, I want to substitute a
variable for "nbc.com". The command:
cmd="dig @4.2.2.2 %s ns +short", % (domname)
does not work. I've tried different variations to no avail. Any advice on how
to get that variable working?
TIA.
--
https://mail.python.org/mailman/listinfo/python-list
Re: passing a variable to cmd
>
> import subprocess
> import shlex
>
> domname = raw_input("Enter your domain name: ");
> print "Your domain name is: ", domname
>
> print "\n"
>
> # cmd='dig @4.2.2.2 nbc.com ns +short'
> cmd="dig @4.2.2.2 %s ns +short", % (domname)
> proc=subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE)
> out,err=proc.communicate()
> print(out)
>
> The line that is commented out works fine. However, I want to substitute
> a variable for "nbc.com". The command:
>
> cmd="dig @4.2.2.2 %s ns +short", % (domname)
>
> does not work. I've tried different variations to no avail. Any advice
> on how to get that variable working?
>
Two things:
1) Please explain what "does not work" mean. Are you getting an error
message? If yes include the entire traceback.
2) The line /* cmd="dig @4.2.2.2 %s ns +short", % (domname) */ gives me a
syntax error. Please copy-and-paste the exact commands you are entering.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Force virtualenv pip to be used
Alec Taylor wrote: > On Sunday, November 6, 2016 at 10:20:53 PM UTC+11, Peter Otten wrote: >> Chris Angelico wrote: >> >> > On Sun, Nov 6, 2016 at 9:17 PM, Alec Taylor >> > wrote: >> >> Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv >> >> 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? >> >> >> >> $ virtualenv a && . "$_"/bin/activate && pip --version >> > >> > I'm pretty sure virtualenv (like venv, about which I'm certain) >> > creates something that you have to 'source' into your shell, rather >> > than running in the classic way: >> > >> > source env/bin/activate >> >> I think this is what the >> >> . "$_"/bin/activate >> >> part of Alec's command is supposed to do. >> >> Yes, that's a dot, not grit on Tim's screen ;) >> >> > It needs to alter environment variables in your shell, which can't be >> > done from a separate program. > > Hmm: > $ echo $PYTHONPATH > /usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/dist- packages > $ pip --version > pip 9.0.0 from /tmp/a/local/lib/python2.7/site-packages (python 2.7) > > > So that worked. Shouldn't PYTHONPATH be set/upserted by the activation of > the virtualenv? That would have been my expectation, but I don't feel competent to recommend changes in pip. Also, to avoid mixing Python 2 and 3, I tend to use pth files to configure non-standard module locations. -- https://mail.python.org/mailman/listinfo/python-list
Re: passing a variable to cmd
On 11/6/2016 6:48 AM, SS wrote: cmd="dig @4.2.2.2 %s ns +short", % (domname) does not work. No kidding. ', %' is a syntax error. The , makes a tuple, the % after string does interpolation. You obviously want the latter so omit the ,. The traceback should have pointed you to where the code became invalid. >>> cmd="dig @4.2.2.2 %s ns +short", % (domname) File "", line 1 cmd="dig @4.2.2.2 %s ns +short", % (domname) ^ This mean that % is not valid GIVEN WHAT HAS COME BEFORE being treated as correct. The , could have been correct, so Python cannot know it is incorrect here. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: passing a variable to cmd
On Sun, Nov 6, 2016 at 10:48 PM, SS wrote: > # cmd='dig @4.2.2.2 nbc.com ns +short' > cmd="dig @4.2.2.2 %s ns +short", % (domname) > proc=subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE) > out,err=proc.communicate() > print(out) > > The line that is commented out works fine. However, I want to substitute a > variable for "nbc.com". The command: Then don't use a single string; use a list of strings: cmd = ["dig", "@4.2.2.2", domname, "ns", "+short"] This is what shlex.split does, and you're fighting against things to try to force everything through that one channel. What happens if someone puts a space in domname? It should come back with an error from dig (you can't have spaces in domain names!), but with naive string interpolation, you would be passing multiple separate arguments. Get used to using lists of arguments for all command execution. Python isn't optimized for keyboard shorthands in running subcommands, the way an interactive shell is; it's designed more to be reliable and dependable. I wouldn't accept a shell that forced me to type commands with all their parts quoted, but I also don't use single strings with Python very often. This is the safer way. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Force virtualenv pip to be used
On Sun, Nov 6, 2016 at 10:19 PM, Peter Otten <[email protected]> wrote: > Chris Angelico wrote: > >> On Sun, Nov 6, 2016 at 9:17 PM, Alec Taylor >> wrote: >>> Running Ubuntu 16.10 with Python 2.7.12+ (default one) and virtualenv >>> 15.0.3 (`sudo -H pip install virtualenv`). What am I doing wrong? >>> >>> $ virtualenv a && . "$_"/bin/activate && pip --version >> >> I'm pretty sure virtualenv (like venv, about which I'm certain) >> creates something that you have to 'source' into your shell, rather >> than running in the classic way: >> >> source env/bin/activate > > I think this is what the > > . "$_"/bin/activate > > part of Alec's command is supposed to do. > > Yes, that's a dot, not grit on Tim's screen ;) Yep, I see that now. Guess my screen's dirty again. Sorry! There are a few possibilities still. 1) You *are* running all this from /tmp, right? "virtualenv a" creates a subdirectory off the current directory, and then you look for /tmp/a. 2) Is there an esoteric interaction between the bash "&&" and the source command? 3) virtualenv could behave differently from venv. It's a third-party package that works by hacks, compared to the properly-integrated venv module. Further research is required. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: pip3 : command not found
On 11/05/2016 11:27 PM, Jon Ribbens wrote: >> 2) If Python notices that its executable comes from a venv, it uses it. > > Yes. My question is *how does it notice*? I'm guessing that it notices by examining the path it was launched from and looks for virtual environment files relative to that path. Here's what a random site said about this (I didn't search long enough to find the official documentation on python.org): "When Python is starting up, it looks at the path of its binary (which, in a virtual environment, is actually just a copy of, or symlink to, your system’s Python binary). It then sets the location of sys.prefix and sys.exec_prefix based on this location, omitting the “bin” portion of the path." This is actually a common idiom in the unix world. For example, busybox works on this principle. You link the busybox executable and call it, say, "cat" and when involved, busybox looks to see how what path it was launched via and then behaves accordingly. -- https://mail.python.org/mailman/listinfo/python-list
Re: Pre-pep discussion material: in-place equivalents to map and filter
2016-11-05 12:47 GMT+01:00 Chris Angelico : > On Sat, Nov 5, 2016 at 9:50 PM, Arthur Havlicek > > But here's the thing. For everyone who writes a decorator function, > there could be dozens who use it. > The day that one guy leaves the team, suddenly you have code that's become a bit tricky to maintain. Our philosophy is that everyone should be able to contribute anywhere although I agree with you: there is such thing as using a decorator as a black box, and even diving into it isn't that hard. Notice I didn't say we don't use these features at all, we just tend to avoid them when a more familiar approach exist. Even so, maybe we are wrong to do so, and the code would be clearer if we used more features. Maybe we just lack the expertise and we are indeed stuck in an old mindset, after all. Anyway, I have some directives to make my code easy to access and must compose with what I would call industrial constraints. As a gambler I can't refuse that bet proposal, no sir :) Expect me to come back with a piece of code and/or questions about CPython engine. -- https://mail.python.org/mailman/listinfo/python-list
[no subject]
Hello! Hope you guys are fine. I am a newbie in programming, though I have been experimenting with Python for close to 3 years, but have never attempt writing any real-life program. However, recently I decided to embark on a personal project to develop a Python App which I want to dedicate to my community to solve a particular calculation challenge relating to financial benefits involving a combination of beneficiaries with different level of benefits. My intention is to use Python 3.4 or 2.7, with Tkinter and Python Megawidgets (Pmw) for the GUI. The following is a short description of the workings of the proposed app: 1. The user inputs the amount to be distributed to the beneficiaries into a text entry box; 2. He clicks add button, to add the value; 3. He selects the beneficiaries from a dropdown list, one at a time; 4. He clicks an “add beneficiary” button to add to the list; 5. He then clicks a button to calculate the amount entitled by each beneficiary; 6. The application then calculates and displays the result in the following format: a. Name: Identity of the beneficiary; b. Percentage: the percentage he is entitled from the amount entered (eg. 4/24, 3/12 etc); c. Value: the monetary value he is entitled (eg $50 for instance) 7. The user then clicks a close button to exit the result window. I don’t have much challenge setting the GUI using Tkinter and Pmw. But my challenge is how to handle the data to be entered, calculate the value based on the percentage each beneficiary is entitled, and allocates same to him/her. This is because: 1. The user can select 3 or 4 beneficiaries with different percentages; 2. Some beneficiaries don’t have a specific percentage, but only got their benefits from a reminder value; 3. Some beneficiaries can have a specific percentage and equally be entitled to a section of the reminder. 4. There may be many scenarios (can extend to 1500, but I want to start experimenting with just 20 instances); I am not too depth in Python but it is the language of my choice since 2010. I don’t know the complex methods which Python provides in order to solve this intricate problem for me. I attempted using the following python codes: # I create different categories of beneficiaries first, using a list. cat1 = [element1, element2, element3, element4] # Capture the values from the user amount = input(“Enter Value: “) choice = input(“Enter Beneficiary: “) # I define a defaultdict object in order to set the values for each beneficiary, as it allows for one-to-many relationship. Result = defaultdict(list) # I now use control flow statements to compare values and distribute. if choice == cat1: result[cat1[0]].append((amount/6) * 1) result[cat1[1]].append((amount/6) * 1) result[cat1[2]].append((amount/6) * 2) result[cat1[3]].append((amount/3) * 2) elif choice == cat2: …continue same approach as above. My Dilemma My challenge here is; the above approach does not provide me the necessary solution. Because: 1. Let’s assume the first part of the if statement gave me the necessary values for the beneficiaries, but running it does not produce anything. It only outputs the storage location of the “result” defaultdict object. What is the best approach, please? 2. I got stocked because I can’t continue using the “if statement” for each and every category of beneficiaries in order to check the user input, since I have to create as many instance as possible; 3. I can’t figure out how to handle the result. Which method can I use to display the result based on the format given above? 4. I presently use list to hold the list of beneficiaries. Based on the short description of the proposed app above, which other container is it suitable for holding the categories of the beneficiaries? I am sorry if I omit any necessary information. This is how far I have gone. I am always ready to provide any necessary details please. Am a newbie, but always ready to learn, no matter what. Thanks in anticipation of your magnanimity. -- Abdallah Salihu Abubakar (Abu Siddeeq) Off Lagos crescent, Unguwar Hausawa, Garki Village, P. O. Box 11617, Garki 91, Abuja - Nigeria 08034592444 [email protected], http://groups.yahoo.com/groups/nurul-islam -- https://mail.python.org/mailman/listinfo/python-list
Re: Pre-pep discussion material: in-place equivalents to map and filter
On Sun, Nov 6, 2016 at 12:50 AM, Arthur Havlicek wrote: > 2016-11-05 12:47 GMT+01:00 Chris Angelico : > >> On Sat, Nov 5, 2016 at 9:50 PM, Arthur Havlicek >> >> But here's the thing. For everyone who writes a decorator function, >> there could be dozens who use it. >> > > The day that one guy leaves the team, suddenly you have code that's become > a bit tricky to maintain. True, and this can become a problem when those dozens have no comprehension of how these features work. But fortunately, all it takes is for one person to step up and learn how decorators are written, and the problem is solved. (And it's not that hard. We teach decorator authorship in our Web Programming In Python course. Not in a huge amount of detail, but enough that a student will be able to carefully tease apart the code of a decorator function and figure out what it's actually doing.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
A Python App To Calculate Sum Of Different Elements In A List With Different Values
Hello! Hope you guys are fine. I am a newbie in programming, though I have been experimenting with Python for close to 3 years, but have never attempt writing any real-life program. However, recently I decided to embark on a personal project to develop a Python App which I want to dedicate to my community to solve a particular calculation challenge relating to financial benefits involving a combination of beneficiaries with different level of benefits. My intention is to use Python 3.4 or 2.7, with Tkinter and Python Megawidgets (Pmw) for the GUI. The following is a short description of the workings of the proposed app: 1. The user inputs the amount to be distributed to the beneficiaries into a text entry box; 2. He clicks add button, to add the value; 3. He selects the beneficiaries from a dropdown list, one at a time; 4. He clicks an “add beneficiary” button to add to the list; 5. He then clicks a button to calculate the amount entitled by each beneficiary; 6. The application then calculates and displays the result in the following format: a. Name: Identity of the beneficiary; b. Percentage: the percentage he is entitled from the amount entered (eg. 4/24, 3/12 etc); c. Value: the monetary value he is entitled (eg $50 for instance) 7. The user then clicks a close button to exit the result window. I don’t have much challenge setting the GUI using Tkinter and Pmw. But my challenge is how to handle the data to be entered, calculate the value based on the percentage each beneficiary is entitled, and allocates same to him/her. This is because: 1. The user can select 3 or 4 beneficiaries with different percentages; 2. Some beneficiaries don’t have a specific percentage, but only got their benefits from a reminder value; 3. Some beneficiaries can have a specific percentage and equally be entitled to a section of the reminder. 4. There may be many scenarios (can extend to 1500, but I want to start experimenting with just 20 instances); I am not too depth in Python but it is the language of my choice since 2010. I don’t know the complex methods which Python provides in order to solve this intricate problem for me. I attempted using the following python codes: # I create different categories of beneficiaries first, using a list. cat1 = [element1, element2, element3, element4] # Capture the values from the user amount = input(“Enter Value: “) choice = input(“Enter Beneficiary: “) # I define a defaultdict object in order to set the values for each beneficiary, as it allows for one-to-many relationship. Result = defaultdict(list) # I now use control flow statements to compare values and distribute. if choice == cat1: result[cat1[0]].append((amount/6) * 1) result[cat1[1]].append((amount/6) * 1) result[cat1[2]].append((amount/6) * 2) result[cat1[3]].append((amount/3) * 2) elif choice == cat2: …continue same approach as above. My Dilemma My challenge here is; the above approach does not provide me the necessary solution. Because: 1. Let’s assume the first part of the if statement gave me the necessary values for the beneficiaries, but running it does not produce anything. It only outputs the storage location of the “result” defaultdict object. What is the best approach, please? 2. I got stocked because I can’t continue using the “if statement” for each and every category of beneficiaries in order to check the user input, since I have to create as many instance as possible; 3. I can’t figure out how to handle the result. Which method can I use to display the result based on the format given above? 4. I presently use list to hold the list of beneficiaries. Based on the short description of the proposed app above, which other container is it suitable for holding the categories of the beneficiaries? I am sorry if I omit any necessary information. This is how far I have gone. I am always ready to provide any necessary details please. Am a newbie, but always ready to learn, no matter what. Thanks in anticipation of your magnanimity. -- -- https://mail.python.org/mailman/listinfo/python-list
Re:
On Sun, Nov 6, 2016 at 12:33 AM, Abdullahi Salihu Abubakar wrote: > [lots of text, taking a representative sample] > 4. I presently use list to hold the list of beneficiaries. Based on the > short description of the proposed app above, which other container is it > suitable for holding the categories of the beneficiaries? > > I am sorry if I omit any necessary information. This is how far I have > gone. I am always ready to provide any necessary details please. Am a > newbie, but always ready to learn, no matter what. > It sounds to me like you have some code. The best way to ask for help about code is to show the code. Show us the smallest program that showcases the problem you're having, and we can help you with it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
A Python App To Calculate Sum Of Different Elements In A List With Different Values
Hello! Hope you guys are fine. I am a newbie in programming, though I have been experimenting with Python for close to 3 years, but have never attempt writing any real-life program. However, recently I decided to embark on a personal project to develop a Python App which I want to dedicate to my community to solve a particular calculation challenge relating to financial benefits involving a combination of beneficiaries with different level of benefits. My intention is to use Python 3.4 or 2.7, with Tkinter and Python Megawidgets (Pmw) for the GUI. The following is a short description of the workings of the proposed app: 1. The user inputs the amount to be distributed to the beneficiaries into a text entry box; 2. He clicks add button, to add the value; 3. He selects the beneficiaries from a dropdown list, one at a time; 4. He clicks an “add beneficiary” button to add to the list; 5. He then clicks a button to calculate the amount entitled by each beneficiary; 6. The application then calculates and displays the result in the following format: a. Name: Identity of the beneficiary; b. Percentage: the percentage he is entitled from the amount entered (eg. 4/24, 3/12 etc); c. Value: the monetary value he is entitled (eg $50 for instance) 7. The user then clicks a close button to exit the result window. I don’t have much challenge setting the GUI using Tkinter and Pmw. But my challenge is how to handle the data to be entered, calculate the value based on the percentage each beneficiary is entitled, and allocates same to him/her. This is because: 1. The user can select 3 or 4 beneficiaries with different percentages; 2. Some beneficiaries don’t have a specific percentage, but only got their benefits from a reminder value; 3. Some beneficiaries can have a specific percentage and equally be entitled to a section of the reminder. 4. There may be many scenarios (can extend to 1500, but I want to start experimenting with just 20 instances); I am not too depth in Python but it is the language of my choice since 2010. I don’t know the complex methods which Python provides in order to solve this intricate problem for me. I attempted using the following python codes: # I create different categories of beneficiaries first, using a list. cat1 = [element1, element2, element3, element4] # Capture the values from the user amount = input(“Enter Value: “) choice = input(“Enter Beneficiary: “) # I define a defaultdict object in order to set the values for each beneficiary, as it allows for one-to-many relationship. Result = defaultdict(list) # I now use control flow statements to compare values and distribute. if choice == cat1: result[cat1[0]].append((amount/6) * 1) result[cat1[1]].append((amount/6) * 1) result[cat1[2]].append((amount/6) * 2) result[cat1[3]].append((amount/3) * 2) elif choice == cat2: …continue same approach as above. My Dilemma My challenge here is; the above approach does not provide me the necessary solution. Because: 1. Let’s assume the first part of the if statement gave me the necessary values for the beneficiaries, but running it does not produce anything. It only outputs the storage location of the “result” defaultdict object. What is the best approach, please? 2. I got stocked because I can’t continue using the “if statement” for each and every category of beneficiaries in order to check the user input, since I have to create as many instance as possible; 3. I can’t figure out how to handle the result. Which method can I use to display the result based on the format given above? 4. I presently use list to hold the list of beneficiaries. Based on the short description of the proposed app above, which other container is it suitable for holding the categories of the beneficiaries? I am sorry if I omit any necessary information. This is how far I have gone. I am always ready to provide any necessary details please. Am a newbie, but always ready to learn, no matter what. Thanks in anticipation of your magnanimity. -- https://mail.python.org/mailman/listinfo/python-list
ANN: released psutil 5.0.0, introducing a 2x speedup for process methods
Hello all, I'm glad to announce the release of psutil 5.0.0: https://github.com/giampaolo/psutil This release introduces important speedups making psutil from 2x to 6x faster depending on what platform you're on. A full blog post can be found here: http://grodola.blogspot.com/2016/11/psutil-500-is-around-twice-as-fast.html About = psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.5 (users of Python 2.4 and 2.5 may use 2.1.3 version). PyPy is also known to work. What's new == *2016-11-06* **Enhncements** - #799: new Process.oneshot() context manager making Process methods around +2x faster in general and from +2x to +6x faster on Windows. - #943: better error message in case of version conflict on import. **Bug fixes** - #932: [NetBSD] net_connections() and Process.connections() may fail without raising an exception. - #933: [Windows] memory leak in cpu_stats() and WindowsService.description(). Links = - Home page: https://github.com/giampaolo/psutil - Download: https://pypi.python.org/pypi/psutil - Documentation: http://pythonhosted.org/psutil - What's new: https://github.com/giampaolo/psutil/blob/master/HISTORY.rst -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Delete h2 until you reach the next h2 in beautifulsoup
On Sunday, November 6, 2016 at 1:27:48 AM UTC-4, [email protected] wrote: > Considering the following html: > > cool stuff hiid="cool"> zz > > and the following list: > > ignore_list = ['example','lalala'] > > My goal is, while going through the HTML using Beautifulsoup, I find a h2 > that has an ID that is in my list (ignore_list) I should delete all the ul > and lis under it until I find another h2. I would then check if the next h2 > was in my ignore list, if it is, delete all the ul and lis until I reach the > next h2 (or if there are no h2s left, delete the ul and lis under the current > one and stop). > > How I see the process going: you read all the h2s from up to down in the DOM. > If the id for any of those is in the ignore_list, then delete all the ul and > li under the h2 until you reach the NEXT h2. If there is no h2, then delete > the ul and LI then stop. > > Here is the full HMTL I am trying to work with: http://pastebin.com/Z3ev9c8N > > I am trying to delete all the UL and lis after "See_also"How would I > accomplish this in Python? I got it working with the following solution: #Remove content I don't want try: for element in body.find_all('h2'): current_h2 = element.get_text() current_h2 = current_h2.replace('[edit]','') #print(current_h2) if(current_h2 in ignore_list): if(element.find_next_sibling('div') != None): element.find_next_sibling('div').decompose() if(element.find_next_sibling('ul') != None): element.find_next_sibling('ul').decompose() except(AttributeError, TypeError) as e: continue -- https://mail.python.org/mailman/listinfo/python-list
Confused with installing per-user in Windows
Dear experts, I need to install some scripts for current user (to skip sudo, UAC popups and whatever). So I make a sdist and use python -m pip install --user This should work for either Python 2 or 3. On Linux, pip installs the scripts into ~/.local/bin ; users are instructed to add this to their PATH if they have not done so already. In Windows, the user-local directory for scripts is %APPDATA%\Python\Scripts. It is not in PATH by default and finding it is hard (because Microsoft made it hidden in their infinite wisdom). But more to this, either Python (2.7 or 3.5) will NOT look there by default. When user types "python myscript.py" or "py myscript.py" he is baffled by "not found". Now, the question: 1. would it be good if python interpreter could JUST find user-local scripts - by default or by some easy configuration option? 2. If not, would it be good to put this smartness into the PY.EXE launcher, make this behavior default or by a simple command line option? So that user can be instructed to type "py myscript [.py]" and it will JUST work, if the script is on existing PATH or in the per-user directory? I know about bdist_wininst and Windows specific install options, but prefer single sdist installer whenever possible. Thanks for reading. --d -- https://mail.python.org/mailman/listinfo/python-list
Re: Confused with installing per-user in Windows
So basically I want to modify py.exe to not only detect the Python version from a script file, but also help locating the script file. -- d -- https://mail.python.org/mailman/listinfo/python-list
Fwd: About Installation.
-- Forwarded message -- From: Avijit Paul Date: Mon, Nov 7, 2016 at 1:27 AM Subject: About Installation. To: [email protected] Hello, I installed python-3.6.0b2-amd64 on my Windows PC. Which is running on 64-bit system of Windows 8.1. The installation was successful. After the installation, when I ran the program it showed the following error, as shows in the attachment. I need your kind help to recover the error showed in the program. Thank You. -- https://mail.python.org/mailman/listinfo/python-list
What is currently the recommended way to work with a distutils-based setup.py that requires compilation?
https://wiki.python.org/moin/WindowsCompilers has now completely
replaced instructions for `distutils`-based packages (starting with
`from distutils.core import setup`) with ones for `setuptools`-based
ones (starting with `from setuptools import setup`).
However, if I have a `distutils`-based `setup.py`, when I run it,
`setuptools` is not used - thus the instructions on the page don't work.
It is possible to run a `distutils`-based script through `setuptools`,
as `pip` does, but it requires the following code
(https://github.com/pypa/pip/blob/8.1.2/pip/req/req_install.py#L849 ):
python -u -c "import setuptools, tokenize;__file__=path>;
exec(compile(getattr(tokenize, 'open', open)(__file__).read()
.replace('\\r\\n', '\\n'), __file__, 'exec'))"
They can't possibly expect me to type that on the command line each
time, now can they?
I also asked this at http://stackoverflow.com/q/40174932/648265 a couple
of days ago (to no avail).
--
Regards,
Ivan
--
https://mail.python.org/mailman/listinfo/python-list
Re: Confused with installing per-user in Windows
On 07.11.2016 4:11, ddbug wrote: Dear experts, I need to install some scripts for current user (to skip sudo, UAC popups and whatever). So I make a sdist and use python -m pip install --user This should work for either Python 2 or 3. On Linux, pip installs the scripts into ~/.local/bin ; users are instructed to add this to their PATH if they have not done so already. In Windows, the user-local directory for scripts is %APPDATA%\Python\Scripts. It is not in PATH by default and finding it is hard (because Microsoft made it hidden in their infinite wisdom). But more to this, either Python (2.7 or 3.5) will NOT look there by default. When user types "python myscript.py" or "py myscript.py" he is baffled by "not found". If `myscript.py' is in the system-wide Scripts (or anywhere else other that current dir), "python myscript.py" will yield "not found" all the same. Now, the question: 1. would it be good if python interpreter could JUST find user-local scripts - by default or by some easy configuration option? Just append `%APPDATA%\Python\Scripts' into your user-specific PATH and use "myscript.py" (without "python") - that will search for the file on PATH and run it with whatever program you have associated with the `.py' extension (which should be `py.exe' if you're using it). 2. If not, would it be good to put this smartness into the PY.EXE launcher, make this behavior default or by a simple command line option? So that user can be instructed to type "py myscript [.py]" and it will JUST work, if the script is on existing PATH or in the per-user directory? I know about bdist_wininst and Windows specific install options, but prefer single sdist installer whenever possible. Thanks for reading. --d -- Regards, Ivan -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: About Installation.
On 2016-11-06 19:36, Avijit Paul wrote: I installed python-3.6.0b2-amd64 on my Windows PC. Which is running on 64-bit system of Windows 8.1. The installation was successful. After the installation, when I ran the program it showed the following error, as shows in the attachment. I need your kind help to recover the error showed in the program. This list doesn't support attachments, so I'm guessing that it's complaining that it can't find "api-ms-win-crd-runtime-l1-1-0.dll". You should already have it if you've kept your PC up to date via Windows Update, but if you haven't, read this: https://support.microsoft.com/en-us/kb/3118401 -- https://mail.python.org/mailman/listinfo/python-list
Re: pip3 : command not found
On 2016-11-06, Chris Angelico wrote: > On Sun, Nov 6, 2016 at 4:27 PM, Jon Ribbens wrote: >>> 2) If Python notices that its executable comes from a venv, it uses it. >> >> Yes. My question is *how does it notice*? > > I could answer this question, but since you don't appear to be > following the thread properly, I'll point out that it's already been > said up above. Go read it. That's not particularly helpful. I have read the entire thread and the question does not appear to have been answered. Could you at least provide the date/date/from (if not a Message-ID) of the post you are talking about please? -- https://mail.python.org/mailman/listinfo/python-list
Re: pip3 : command not found
On 2016-11-06, Michael Torrie wrote: > I'm guessing that it notices by examining the path it was launched from > and looks for virtual environment files relative to that path. Indeed, the mysterious thing is what are "virtual environment files"? The official docs say "A venv is a directory tree which contains Python executable files and other files which indicate that it is a venv." but don't explain what they mean by "other files". > Here's what a random site said about this (I didn't search long enough > to find the official documentation on python.org): > > "When Python is starting up, it looks at the path of its binary (which, > in a virtual environment, is actually just a copy of, or symlink to, > your system’s Python binary). It then sets the location of sys.prefix > and sys.exec_prefix based on this location, omitting the “bin” portion > of the path." Aha! This is progress. OK, I've done some more investigation and it looks like the above description is not exactly accurate. The magic is actually all in site.py by the looks of it. This looks at argv[0] (effectively - it's actually using sys.executable) and then looks for ./pyvenv.cfg and ../pyvenv.cfg relative to that file. Only if one of those files exists does it then set sys.prefix to .. relative to sys.executable and then sys.path is set using various hard-coded paths relative to sys.prefix. So the answer to my original question is that Python knows it's in a venv "if there exists a file called pyvenv.cfg in the same directory as or the parent directory of the python exeuctable". It also appears that this feature was added in Python 3.3, so being able to run the venv python directly presumably only works on that version and later. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Theory] How to speed up python code execution / pypy vs GPU
"Mr. Wrobel" writes: > ... > However the same skeptics told my that, ok we believe that it is true, > however the code execution is much slower than any other compiled > language. However, in many cases "code execution speed" is not the primary concern. In my experience, "development speed" is far superior with Python than with e.g. C, C++ or Java. Even for programs for which "code execution speed" is important, the importance often affects only quite local portions of the program. For those portions, I look for existing C/C++ libraries or I implement them myself in "C/C++", maybe with the help of "cython". -- https://mail.python.org/mailman/listinfo/python-list
