Re: [Tutor] Does the secrets module in Python 3.6 use a hardware RNG like that provided in Intel CPUs?

2018-03-11 Thread Steven D'Aprano
Hi Simon,

On Fri, Mar 09, 2018 at 10:07:14PM +, Simon Connah via Tutor wrote:
> Hi,
> I was reading through the secrets documentation in Python 3.6 and 
> noticed that it uses /dev/urandom but I'm unsure if that means it'll 
> use a hardware RNG or just one provided by the operating system (Linux 
> / Windows / etc) in software.

Getting cryptographic-quality random numbers right is very hard, and 
that's not something which the Python core developers have either the 
experience or desire to do. So the secrets module is an interface to the 
operating system's source of randomness.

If your operating system uses a hardware RNG for /dev/urandom (or the 
equivalent for Windows), then so will the secrets module. If it doesn't, 
then neither will secrets.

In other words, Python trusts the operating system. Generally speaking, 
most people should too. Most major operating systems, including Windows, 
Linux, OS X, and various Unixes have well-respected RNGs which are 
generally considered secure.

But of course there's a lot we don't know about the state of the art of 
*secret* crypto research and the capabilities of major government 
intelligence agencies. What little we do know, we can thank a handful of 
people like Edward Snowden and a few other unnamed whistle-blowers who 
have leaked NSA documents.

And flaws could be discovered at any time. Naturally, if a flaw is 
discovered, the secrets module cannot magically patch it or replace the 
software with something else. That's up to the operating system.


> The question is is it possible to 
> determine the source of the randomness from os.urandom if there was 
> ever a flaw found in a particular hardware RNG?

You have to ask your OS developers about that, but the secrets module 
doesn't support anything like that. It can't peer inside the OS and 
determine how os.urandom works.

Certainly you are right to be cautious about hardware RNGs. Back in 2013 
it has become clear that the NSA at least (if not other intelligence 
agencies) have compromised or inserted backdoors into many if not all 
hardware-based RNGs in common use:

http://www.nytimes.com/2013/09/06/us/nsa-foils-much-internet-encryption.html?pagewanted=all


So if you are using a commercially available hardware RNG, you should 
assume that the Five Eyes countries (the USA, UK, Australia, Canada and 
New Zealand) have compromised it.

In the case of Linux, at least, /dev/urandom will use the output of the 
hardware RNG, but it is mixed in with other sources of cryptographically 
strong randomness and is believed to be safe.

https://plus.google.com/+TheodoreTso/posts/SDcoemc9V3J


> I'm 
> just a bit curious about the whole "will always use the strongest 
> source for pseudo-random numbers" when research could change that 
> assumption overnight based on discovered flaws.

The full quote is:

"The secrets module provides access to the most secure source of 
randomness THAT YOUR OPERATING SYSTEM PROVIDES." [emphasis added]

https://docs.python.org/3/library/secrets.html

So don't imagine that the secrets module has access to the cutting edge 
classified crypto technology used by the NSA :-)

If you have any other questions, please feel free to ask on the mailing 
list, and I will do my best to answer.

By the way, I am the author of the secrets module:

https://www.python.org/dev/peps/pep-0506/

If you haven't already read the PEP (Python Enhancement Proposal), you 
should, it contains a lot of background for why the secrets module was 
invented.


> This is probably a 
> really stupid question and if it is I apologise but I'm somewhat 
> confused.

No need to apologise! Hope I cleared up your confusion, and if not, 
please feel free to ask anything else that concerns you.

Regards,


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] help with code

2018-03-11 Thread Leslie SimondeMontfort via Tutor
Hi, I wondered if there is someone that can help me with this code.  Thank you, 
Leslie

## Text menu in Python

def print_menu():   ## Your menu design here
print 30 * "-" , "MENU" , 30 * "-"
print "1. Menu login 1"
print "2. Menu create an account 2"
print "3. Menu list all accounts 3"
print "4. Quit"
print 67 * "-"

loop!=4

while loop:  ## While loop which will keep going until loop = False
print_menu()## Displays menu
choice = input("Enter your choice [1-4]: ")
 
if choice==1:"Menu login 1"
count = 0 
while True: 
  def User():
login = raw_input("Enter login name: ")
passw = raw_input("Enter password: ")

# check if user exists and login matches password
if login in users and users[login] == passw: 
print "\nLogin successful!\n"
else:
print "\nUser doesn't exist or wrong password!\n"
if choice == 3:
print("Too many attempts.")
exit()


for val in "string":
if val == "i":
break
print(val)

print("The end")
   
   if choice==2: 
   print " Menu create an account 2"


def main():
register()

def register():
username = input("Please input your desired username ")
password = input("Please input your desired password ")
 if not username or not password:
print "Enter a valid username and password..."
users = c.get_all_users()
userList = users['list_users_response']['list_users_result']['users']
if username in userList:
print "username already exist"
else:
# I just want to create if fields are not empty and if username 
dont exist
c.create_user(username)
file = open("credential.txt","a")
file.write(username)
file.write(" ")
file.write(password)
file.close()
login()

 if choice==3: 
  
 def login():
check = open("credential.txt","r")
username = input("Please enter your username")
password = input("Please enter your password")

 def thank_you():
  print("Thank you for signing up at our website!.")
  
elif choice == "q":
exit()
Sent from Mail for Windows 10

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with code

2018-03-11 Thread Joel Goldstick
On Sat, Mar 10, 2018 at 11:20 PM, Leslie SimondeMontfort via Tutor <
tutor@python.org> wrote:

> Hi, I wondered if there is someone that can help me with this code.  Thank
> you, Leslie
>
> ## Text menu in Python
>
> def print_menu():   ## Your menu design here
> print 30 * "-" , "MENU" , 30 * "-"
> print "1. Menu login 1"
> print "2. Menu create an account 2"
> print "3. Menu list all accounts 3"
> print "4. Quit"
> print 67 * "-"
>
> loop!=4
>
> while loop:  ## While loop which will keep going until loop = False
> print_menu()## Displays menu
> choice = input("Enter your choice [1-4]: ")
>
> if choice==1:"Menu login 1"
> count = 0
> while True:
>   def User():
> login = raw_input("Enter login name: ")
> passw = raw_input("Enter password: ")
>
> # check if user exists and login matches password
> if login in users and users[login] == passw:
> print "\nLogin successful!\n"
> else:
> print "\nUser doesn't exist or wrong password!\n"
> if choice == 3:
> print("Too many attempts.")
> exit()
>
>
> for val in "string":
> if val == "i":
> break
> print(val)
>
> print("The end")
>
>if choice==2:
>print " Menu create an account 2"
>
>
> def main():
> register()
>
> def register():
> username = input("Please input your desired username ")
> password = input("Please input your desired password ")
>  if not username or not password:
> print "Enter a valid username and password..."
> users = c.get_all_users()
> userList = users['list_users_response']['
> list_users_result']['users']
> if username in userList:
> print "username already exist"
> else:
> # I just want to create if fields are not empty and if
> username dont exist
> c.create_user(username)
> file = open("credential.txt","a")
> file.write(username)
> file.write(" ")
> file.write(password)
> file.close()
> login()
>
>  if choice==3:
>
>  def login():
> check = open("credential.txt","r")
> username = input("Please enter your username")
> password = input("Please enter your password")
>
>  def thank_you():
>   print("Thank you for signing up at our website!.")
>
> elif choice == "q":
> exit()
> Sent from Mail for Windows 10
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

A quick look shows you are using print statements and print functions.  So,
are you using python 3 or python 2?  What exactly are you asking about?

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with code

2018-03-11 Thread Alan Gauld via Tutor
On 11/03/18 04:20, Leslie SimondeMontfort via Tutor wrote:
> Hi, I wondered if there is someone that can help me with this code. 

I'll try but theres a lot to comment on.
See below...

> def print_menu():   ## Your menu design here
> print 30 * "-" , "MENU" , 30 * "-"
> print "1. Menu login 1"
> print "2. Menu create an account 2"
> print "3. Menu list all accounts 3"
> print "4. Quit"
> print 67 * "-"
> 
> loop!=4

That last line makes no sense. Its a boolean expression using an
undeclared variable(loop) You should get a name error when you run
it.

> while loop:  ## While loop which will keep going until loop = False

Again you reference loop but you have not assigned any
value to it. You should get an error here too.

> print_menu()## Displays menu
> choice = input("Enter your choice [1-4]: ")

This is the end of your while loop and you have not modified
the test condition (loop) so even if loop existed this would
just loop forever. One of the fundamental principles of while
loops is that you must either modify the test condition
somehow or use a break somewhere inside the loop.

Also using input to convert your data is a bad design. ijput is very
insecure and users could (deliberately or by accident) type values which
python then executes and cause damagew, in extreme cases even crashing
your computer. Its much better to explicitly convert the raw_input string:

 choice = int(raw_input("Enter your choice [1-4]: "))

To catch invalid input wrap it in a try/except block...


> if choice==1:"Menu login 1"
>   count = 0

This doesn't work either. You have an if test where the
body is the single line containing the string. It doesn't
do anything  although it is legal Python but...
The next line is indented as if it were part of the if
block but it isn't so you should get an error there too.

> while True: 
>   def User():
> login = raw_input("Enter login name: ")
> passw = raw_input("Enter password: ")
> 
> # check if user exists and login matches password
> if login in users and users[login] == passw: 
> print "\nLogin successful!\n"
> else:
> print "\nUser doesn't exist or wrong password!\n"
> if choice == 3:
> print("Too many attempts.")
> exit()

Now you have a loop that will go forever continually defining
(but not calling) a function.

Inside the function you might want to check the getpass
function from the getpass module for a more secure password
input. If you are on Unix/Linux/MacOS you could also look
at the pwd module for ways of validating the user.

Fiunally note that the if coice === 3 line is inside
the invalid user block so would only be executed if it
was an invalid user - which seems wrong?

In fact I'd suggest that if block should not even be
inside the User() function at all. Its not really checking
anything about the user, its checking what the user did.
Try to keep your functions purpose clear and distinct,
don't mix functionality in a single function.

> for val in "string":
> if val == "i":
> break

This assigns val to s,then t then r then i so it will allways break on
the 4th cycle.

You might as well just write

for val in 'str':

> print(val)

And since you just print val you might as well miss out the loop and use

print('s\nt\nr\n')

> print("The end")
>
>if choice==2: 
>print " Menu create an account 2"

This is indented but there is no enclosing block so
should give an indentation error.

> def main():
> register()
> 
> def register():
> username = input("Please input your desired username ")
> password = input("Please input your desired password ")
>  if not username or not password:
> print "Enter a valid username and password..."
> users = c.get_all_users()
> userList = users['list_users_response']['list_users_result']['users']

Note the indentation is all over the place.
Python is fussy about consistent indentation, you will get errors here.

Also you reference c but c does not appear anywhere else.
What is c?

The remaining code has more of the same so I'll stop here.
I think you need to strip this back and get the basic structure working
first before trying to add all the other functions.

print a menu, read the input and print the users choice.
Exit when option 4 is used.

Get that working then you can add the code to process
the choices one by one. Get each choice working before
adding the next.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with code

2018-03-11 Thread Cameron Simpson

On 10Mar2018 23:20, Leslie SimondeMontfort  wrote:

Hi, I wondered if there is someone that can help me with this code.  Thank you, 
Leslie


Generally we like to know what you think is wrong with it. For example, what 
you expected it to do, and a little transcript of what it actually did 
(cut/paste the text from your terminal/console straight in this email, complete 
with any stack traces that came with it, if there were any).


This looks like homework, and we're generally happy to help if you'll explain 
what you're trying to achieve and show the code you have so far. I'm glad to 
see you've included all your code here, it is usually necessary.


Absent an actual error transcript I can make a few general remarks about the 
code which might lead you towards making it work the way you intend it to.


Remarks inline below, in the code:


## Text menu in Python

def print_menu():   ## Your menu design here
   print 30 * "-" , "MENU" , 30 * "-"
   print "1. Menu login 1"
   print "2. Menu create an account 2"
   print "3. Menu list all accounts 3"
   print "4. Quit"
   print 67 * "-"

   loop!=4


The line above "loop!=4" is a simple expression. It is valid, but useless.  
Normally a test with be part of a statement, such as the condition in an "if" 
or "while".


Also, because it is indented it is inside the "print_menu" function,
which doesn't seem very relevant - the function shouldn't care about
the value of "loop".


while loop:  ## While loop which will keep going until loop = False


You haven't set a value to "loop" yet, so this code will raise an exception as 
soon as you try to test "loop". Probably it should be set to True before the 
loop begins.



   print_menu()## Displays menu
   choice = input("Enter your choice [1-4]: ")

if choice==1:"Menu login 1"
count = 0


Indentation is important in Python. Because this "if" statement is not 
indented, it is outside the "while" loop above. It looks like you while loop is 
meant to offer menu choices until the user chooses "Quit". So all the code 
acting on those choices needs to be inside the loop, and thus indents the same 
as the 2 lines above it which print the menu and read the choice.


You're setting "count = 0" but I don't see you use "count" elsewhere.


while True:
 def User():
   login = raw_input("Enter login name: ")
   passw = raw_input("Enter password: ")

   # check if user exists and login matches password
   if login in users and users[login] == passw:
   print "\nLogin successful!\n"
   else:
   print "\nUser doesn't exist or wrong password!\n"
   if choice == 3:
   print("Too many attempts.")
   exit()


This probably doesn't do what you imagine. A "def" statement is a statement, to 
be run. This loop runs forever, but all it does in the loop is _define_ the 
function "User". It never calls the function. So it will just run forever, 
redefining the function again and again.


Probably you need to define the function _before_ the loop, and actually call 
the function inside the loop.


Normally all your function definitions will be outside the main code, so the 
"User" function definition should be above this, for example right underneath 
your "print_menu" function definition. Likewise your other functions.



for val in "string":
   if val == "i":
   break
   print(val)


I presume this is just a little exercise loop to print some of the leading 
characters from the string "string".



print("The end")

  if choice==2:
  print " Menu create an account 2"


This "if" statement _is_ indented correctly for the main loop you set up 
earlier, but all the intervening code will be getting in the way. Once you have 
all the function definitions up the top of your code things will work better.


def main():
   register()


Note that this just defines a "main" function. Nothing seems to call it.


def register():
   username = input("Please input your desired username ")
   password = input("Please input your desired password ")
if not username or not password:


This "if" is indented differently to the other statements in this function. It 
needs to move left one space.


You seem to be using Python 2. In Python 2, input() actually evaluates the 
input string as a Python expression. This is why you got an integer earlier 
when you prompted the user for "choice". However, when reading strings such as 
usernames or passwords you need to use raw_input(), not input(). raw_input() 
just reads the string and returns it.



   print "Enter a valid username and password..."


Here's you are admonishing the user for entering an empty username or password.  
However you don't then do anything about it; instead your code falls through 
and starts setting up the user.


You probably want a loop shapes more like this (totally untested):

   while True:
   username = input("Please input your desired username ")
   if len(username) == 0:
   print("Empty username rejected.")

Re: [Tutor] help with code

2018-03-11 Thread Bob Gailer
On Mar 11, 2018 6:25 AM, "Leslie SimondeMontfort via Tutor" <
tutor@python.org> wrote:
>
> Hi, I wondered if there is someone that can help me with this code.

I have to assume that you are very new to python. Have you written a Python
program that runs the way you want it to?

It is often useful to start by writing a very simple program that contains
one aspect of the problem you're trying to solve, then getting that program
to run. Then you add another feature and get that to run.

When you run into a problem, then email us the code, and tell us what
version of python you're using, what you did to run the program, what
results you expected, and what results you got. You can often handle the
latter by copying and pasting the execution. If the result was a traceback
be sure to include the entire traceback.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with code

2018-03-11 Thread Abdur-Rahmaan Janhangeer
 print 30 * "-" , "MENU" , 30 * "-"

# just tested in py3 you can do
# 'MENU'.center(67, '-')

On Sun, Mar 11, 2018 at 8:20 AM, Leslie SimondeMontfort via Tutor <
tutor@python.org> wrote:

> Hi, I wondered if there is someone that can help me with this code.  Thank
> you, Leslie
>
> ## Text menu in Python
>
> def print_menu():   ## Your menu design here
> print 30 * "-" , "MENU" , 30 * "-"
> print "1. Menu login 1"
> print "2. Menu create an account 2"
> print "3. Menu list all accounts 3"
> print "4. Quit"
> print 67 * "-"
>
> loop!=4
>
> while loop:  ## While loop which will keep going until loop = False
> print_menu()## Displays menu
> choice = input("Enter your choice [1-4]: ")
>
> if choice==1:"Menu login 1"
> count = 0
> while True:
>   def User():
> login = raw_input("Enter login name: ")
> passw = raw_input("Enter password: ")
>
> # check if user exists and login matches password
> if login in users and users[login] == passw:
> print "\nLogin successful!\n"
> else:
> print "\nUser doesn't exist or wrong password!\n"
> if choice == 3:
> print("Too many attempts.")
> exit()
>
>
> for val in "string":
> if val == "i":
> break
> print(val)
>
> print("The end")
>
>if choice==2:
>print " Menu create an account 2"
>
>
> def main():
> register()
>
> def register():
> username = input("Please input your desired username ")
> password = input("Please input your desired password ")
>  if not username or not password:
> print "Enter a valid username and password..."
> users = c.get_all_users()
> userList = users['list_users_response']['
> list_users_result']['users']
> if username in userList:
> print "username already exist"
> else:
> # I just want to create if fields are not empty and if
> username dont exist
> c.create_user(username)
> file = open("credential.txt","a")
> file.write(username)
> file.write(" ")
> file.write(password)
> file.close()
> login()
>
>  if choice==3:
>
>  def login():
> check = open("credential.txt","r")
> username = input("Please enter your username")
> password = input("Please enter your password")
>
>  def thank_you():
>   print("Thank you for signing up at our website!.")
>
> elif choice == "q":
> exit()
> Sent from Mail for Windows 10
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Abdur-Rahmaan Janhangeer
https://github.com/abdur-rahmaanj
Mauritius
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] prime factorisation

2018-03-11 Thread Bernd Hewener
Dear python tutors,

for training purposes, I am writing a Python program for prime factorisation.

Functions for reading in the number and finding the primes are working alright 
(of Course, finding primes up to ½ Number would suffice).

Still, the function for finding the factorization itsel does not work. I am not 
sure, but the number i running through the primes for checking does not seem to 
work properly.

Would you please be so kind as to help?

Thank you very much.

Best wishes,

Bernd


# This program calculates the prime factors of a number entered.

primefactors = []

n, num = 0, 0

def readin():
print ("Readin")
while True:
num = input("Please enter a positive integer n for prime factorization. 
")
try:
n = int(num)
return n
except ValueError or num < 1:
print("Please enter a _positive_ integer!")
else:
break

def prime_find(l):
#print ("Primefind " + str(l))
primes = []
for num in range(2, l + 1):
for i in primes:
if (num % i) == 0:
break
else:
primes.insert(0, num)
return primes

def prime_factorization(k):
print ("Prime factorization")
prime_facs = []
for i in range(len(prime_find(k)):
while k % i == 0:
prime_facs.insert(0, i)
k = k / i
else:
break
return prime_facs

number = readin()
primes = prime_find(number)
print ("Prime numbers up to " + str(number) + " are:")
print (primes)
prime_factor = prime_factorization(number)
print (prime_factor)

"""def PrimFaktorZerlegung(n):
  #Primen enthält Primzahlen. Wir hoffen, dass 
  #alle Primteiler in diese List zu finden sind.
  #Sie kann ein Parameter, oder ein Klasskonstant sein
  for p in range(len(Primen)):
while n % p == 0:
  Teiler.append(p)
   n = n/p
  return Teiler"""

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Virtual environment question

2018-03-11 Thread Jim
It was my understanding that using a virtual environment kept everything 
isolated in that environment. So I was surprised when I got the 
following error message.


(env) jfb@jims-mint18 ~ $


File 
"/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", 
line 528, in _request

resp = opener.open(request, timeout=self._timeout)

  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
response = self._open(req, data)


I snipped most of the error msg because for the purpose of this question 
I am not interested in them. I tried  something that I did not think 
would work and it did not.


I am wondering why the path for the first line and every line above it 
is /home/jfb/EVs/env and the second line and everything after is is

/usr/lib/.

I didn't think anything from my system python would be involved if I 
started from a virtual environment.


Regards,  Jim


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Virtual environment question

2018-03-11 Thread Jim

On 03/11/2018 05:54 PM, Cameron Simpson wrote:

Note: This message came straight to me and I haven't seen it on the list 
yet. Hopefully this reply will make it to the list.



On 11Mar2018 15:52, jim  wrote:
It was my understanding that using a virtual environment kept 
everything isolated in that environment. So I was surprised when I got 
the following error message.


(env) jfb@jims-mint18 ~ $


File 
"/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", 
line 528, in _request

   resp = opener.open(request, timeout=self._timeout)

 File "/usr/lib/python3.5/urllib/request.py", line 466, in open
   response = self._open(req, data)


I snipped most of the error msg because for the purpose of this 
question I am not interested in them. I tried  something that I did 
not think would work and it did not.


I am wondering why the path for the first line and every line above it 
is /home/jfb/EVs/env and the second line and everything after is is

/usr/lib/.

I didn't think anything from my system python would be involved if I 
started from a virtual environment.


It is possible to make a virtualenv which references the osurce python's 
library. These days the default is isolation, but older virtualenvs used 
to hook to the original python by default. This is controlled by 
virtualenv's --system-site-packages and --no-site-packages. Maybe you 
should build the env again using --no-site-packages explicitly and see 
if the behaviour changes.


If you're not using the "virtualenv" command to make the environment, 
please tell use exactly how it was made (there are other tools for the 
same purpose).


In fact, tell us regardless. It aids debugging.

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)


I installed pyvenv in Jan 17 using synaptic on  Mint 18.

Here are the contents of the pyvenv cfg file:

home = /usr/bin
include-system-site-packages = false
version = 3.5.2

It's been awhile so I don't remember that much about the installation. I 
really don't know that much about virtual environments so I am guessing 
I accepted the defaults for the installation.


Just to be complete here is the entire error msg:

Traceback (most recent call last):
  File "/home/jfb/MyProgs/Scripts/login_af.py", line 36, in 
driver = webdriver.Remote(desired_capabilities=caps)
  File 
"/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", 
line 154, in __init__

self.start_session(desired_capabilities, browser_profile)
  File 
"/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", 
line 243, in start_session

response = self.execute(Command.NEW_SESSION, parameters)
  File 
"/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", 
line 310, in execute

response = self.command_executor.execute(driver_command, params)
  File 
"/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", 
line 466, in execute

return self._request(command_info[0], url, body=data)
  File 
"/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", 
line 528, in _request

resp = opener.open(request, timeout=self._timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
'_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
raise URLError(err)
urllib.error.URLError: 

If you tell me where to look, I'd be happy to provide any more info you 
need.



Regards,  Jim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Virtual environment question

2018-03-11 Thread Cameron Simpson

On 11Mar2018 15:52, jim  wrote:
It was my understanding that using a virtual environment kept 
everything isolated in that environment. So I was surprised when I got 
the following error message.


(env) jfb@jims-mint18 ~ $


File "/home/jfb/EVs/env/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", 
line 528, in _request

   resp = opener.open(request, timeout=self._timeout)

 File "/usr/lib/python3.5/urllib/request.py", line 466, in open
   response = self._open(req, data)


I snipped most of the error msg because for the purpose of this 
question I am not interested in them. I tried  something that I did 
not think would work and it did not.


I am wondering why the path for the first line and every line above it 
is /home/jfb/EVs/env and the second line and everything after is is

/usr/lib/.

I didn't think anything from my system python would be involved if I started 
from a virtual environment.


It is possible to make a virtualenv which references the osurce python's 
library. These days the default is isolation, but older virtualenvs used to 
hook to the original python by default. This is controlled by virtualenv's 
--system-site-packages and --no-site-packages. Maybe you should build the env 
again using --no-site-packages explicitly and see if the behaviour changes.


If you're not using the "virtualenv" command to make the environment, please 
tell use exactly how it was made (there are other tools for the same purpose).


In fact, tell us regardless. It aids debugging.

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] [Pandas] - Creating a bigger dataframe by using one minor dataframe as variable of another minor dataframe

2018-03-11 Thread Henrique C. S. Junior
I’m working with two dataframes obtained from the infrared spectroscopy
analysis  (yes, we’re scientists trying to work better using python).
The dataframes are as follows:

***DATA1:***

IRRAMAN   CM-1
 245.54  730.41  3538.10   s1 100
   3.93  204.17  3237.13   s6 93
  11.13  477.42  3233.43   s3 14   s5 76
   3.44  136.83  3229.53   s3 -78   s5 15
   6.40  363.33  3219.42   s7 94
   8.02  296.03  3217.14   s2 -90
   6.13   80.90  3209.69   s9 93
   3.43  166.41  3204.74   s4 -92
   8.91  146.43  3203.92   s8 94
26.77  201.97  3168.99   s10 82   s12 -18


***DATA2:***

s 1 1.00   STRE   14   21   NH1.015055  f3538 100
s 2 1.00   STRE1   22   CH1.081994  f3217 90
s 3-1.00   STRE1   22   CH1.081994  f3233 14  f3230 78
s 4 1.00   STRE4   23   CH1.082576  f3205 92
s 5 1.00   STRE   19   26   CH1.080387  f3237 93
s 7 1.00   STRE   17   28   CH1.083210  f3219 94
s 8 1.00   STRE   17   28   CH1.083210  f3204 94
s 571.00   BEND   11   12   14   CCN   129.85  f940 20
s 581.00   BEND   19   18   15   CCC   120.65
s 59   -1.00   BEND   15   17   20   CCC   120.28  f1037 32  f842 10
s 601.00   BEND   118   10   CCO   122.22  f402 38
s 61   -1.00   BEND8   11   13   CCCl   114.81  f221 60  f194 11d
s 931.00   OUT30   19   20   16   OCCC 0.17  f864 14  f746
11  f535 17  f517 11
s 941.00   OUT 7613    0.48  f829 10  f172
41
s 951.00   OUT17   14   18   15   CNCC 3.64  f564 16  f535
15  f396 10
s 961.00   OUT106   118   OCCC 0.74  f822 63

At this point, they are both (after a LOT of work) converted into a pandas
dataframe but, as a final result, I’d like to create one big dataframe
because those two are related by the variables s1, s2, s3, s4 and so on.
So, I’d like to insert the variables s1, s2, s3, sn every time they appear
in the DATA1:

***DATA1 with DATA2:***
*(I tried to use ** to show you every time DATA 2 was inserted into DATA1)*

IRRAMAN   CM-1
 245.54  730.41  3538.10   *s1* 100 ***STRE   14   21   NH1.015055*
**
   3.93  204.17  3237.13   *s6* 93 ***STRE   19   26   CH1.080387*
**
  11.13  477.42  3233.43   *s3* ***14 STRE1   22   CH1.081994***
 *s5* 76 ***STRE   19   26   CH1.080387***
   3.44  136.83  3229.53   *s3* -78 ***STRE1   22   CH1.081994***
*s5* 15  ***STRE   19   26   CH 1.080387***

Observe that some lines can have more than two variables.
I have to admit that I’m completely lost using pandas right now and any
help is much appreciated.

Thanks in advance.

-- 
*Henrique C. S. Junior*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor