[Tutor] (no subject)
Hi there! How are you? I need an advise. I need to get values from html form, but form.getvalues['query'] returns None. Incorporated in function and not. The aim is to get the user input after filling form and clicking submit button. Here is a piece of code: form = cgi.FieldStorage() A = ['Course_Name', 'Gender', 'Phone_No', 'Residential_Address', 'Student_LastName', 'Student_FirstName', 'Password'] data_values = {}for i in dict(form).keys(): if i in A: data_values[(str(i))] = "'" + dict(form)[str(i)].value + "'" course, gender, phone, adress, last_name, first_name, password= [data_values[i] for i in sorted(data_values.keys())] And this is a fragment of html: What could be the reason? What can I do? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Белякова Анастасия wrote: > Hi there! How are you? > I need an advise. > > I need to get values from html form, but form.getvalues['query'] returns > None. I took a quick look into the cgi module, and FieldStorage class doesn't seem to have a getvalues attribute. You should get an exception rather than a None value. For easier debugging make sure your script starts with the lines #!/usr/bin/env python3 import cgitb cgitb.enable() > Incorporated in function and not. The aim is to get the user input > after filling form and clicking submit button. Here is a piece of code: > > form = cgi.FieldStorage() > > A = ['Course_Name', 'Gender', 'Phone_No', 'Residential_Address', > 'Student_LastName', > 'Student_FirstName', 'Password'] > data_values = {}for i in dict(form).keys(): > if i in A: > data_values[(str(i))] = "'" + dict(form)[str(i)].value + "'" > > > > course, gender, phone, adress, last_name, first_name, password= > [data_values[i] for i in sorted(data_values.keys())] > > And this is a fragment of html: > > method="post" onsubmit="return ValidateForm()"> > > style="font-weight: 700"/> > > What could be the reason? What can I do? Remove as much as you can from your script. E. g., does the following script show the contents of the form when you replace your current Hello.py with it? #!/usr/bin/env python3 import cgitb cgitb.enable() import cgi import sys sys.stdout.write("Content-type: text/html\r\n\r\n") print("") try: form = cgi.FieldStorage() cgi.print_form(form) except: cgi.print_exception() print("") If it doesn't double-check your setup (is the script executable, is your server configured properly etc.); once the basics work put stuff back in until the code does what you want -- or breaks. Then you can at least point to the exact statement that causes the breakage. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Euclidean Distances between Atoms in a Molecule.
I am trying to port a program that I wrote in FORTRAN twenty years ago into Python 3 and am having a hard time trying to calculate the Euclidean distance between each atom in the molecule and every other atom in the molecule. Here is a typical table of coordinates: MASS X Y Z 0 12.011 -3.265636 0.198894 0.090858 1 12.011 -1.307161 1.522212 1.003463 2 12.011 1.213336 0.948208 -0.033373 3 14.007 3.238650 1.041523 1.301322 4 12.011 -5.954489 0.650878 0.803379 5 12.011 5.654476 0.480066 0.013757 6 12.011 6.372043 2.731713 -1.662411 7 12.011 7.655753 0.168393 2.096802 8 12.011 5.563051 -1.990203 -1.511875 91.008 -2.939469 -1.327967 -1.247635 10 1.008 -1.460475 2.993912 2.415410 11 1.008 1.218042 0.451815 -2.057439 12 1.008 -6.255901 2.575035 1.496984 13 1.008 -6.560562 -0.695722 2.248982 14 1.008 -7.152500 0.390758 -0.864115 15 1.008 4.959548 3.061356 -3.139100 16 1.008 8.197613 2.429073 -2.588339 17 1.008 6.503322 4.471092 -0.543939 18 1.008 7.845274 1.892126 3.227577 19 1.008 9.512371 -0.273198 1.291080 20 1.008 7.147039 -1.365346 3.393778 21 1.008 4.191488 -1.928466 -3.057804 22 1.008 5.061650 -3.595015 -0.302810 23 1.008 7.402586 -2.392148 -2.374554 What I need for further calculation is a matrix of the Euclidean distances between the atoms. So far in searching the Python literature I have only managed to confuse myself and would greatly appreciate any pointers towards a solution. Thanks in advance. -- Stephen P. Molnar, Ph.D.Life is a fuzzy set www.molecular-modeling.net Stochastic and multivariate (614)312-7528 (c) Skype: smolnar1 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Euclidean Distances between Atoms in a Molecule.
On 02/04/17 18:41, Stephen P. Molnar wrote: > I am trying to port a program that I wrote in FORTRAN twenty years ago > into Python 3 and am having a hard time trying to calculate the > Euclidean distance between each atom in the molecule and every other > atom in the molecule. Sounds highly specialized. Remember this is a general language tutor group and very few of us even know what Euclidean distances between atoms might mean let alone how to calculate them. You need to either ask on a more technical group (such as the SciPy forum maybe?) or provide the context so we know what you are talking about. Its easy for experts to forget just how little the rest of humanity knows about their area. >MASS X Y Z > 0 12.011 -3.265636 0.198894 0.090858 > 1 12.011 -1.307161 1.522212 1.003463 > 2 12.011 1.213336 0.948208 -0.033373 > 3 14.007 3.238650 1.041523 1.301322 > 4 12.011 -5.954489 0.650878 0.803379 > > What I need for further calculation is a matrix of the Euclidean > distances between the atoms. > > So far in searching the Python literature I have only managed > to confuse myself Where are you searching and what for? You are very unlikely to find any references to Euclidean maths in the standard library of docs. You might find them in the SciPy forums. What have you tried? How did it fail? -- 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] Euclidean Distances between Atoms in a Molecule.
On Sun, Apr 02, 2017 at 01:41:27PM -0400, Stephen P. Molnar wrote: > I am trying to port a program that I wrote in FORTRAN twenty years ago > into Python 3 and am having a hard time trying to calculate the > Euclidean distance between each atom in the molecule and every other > atom in the molecule. > > Here is a typical table of coordinates: > > > MASS X Y Z > 0 12.011 -3.265636 0.198894 0.090858 > 1 12.011 -1.307161 1.522212 1.003463 [...] > What I need for further calculation is a matrix of the Euclidean > distances between the atoms. It is quite likely that the third-party Numpy or Scipy packages include read-made solutions to this. It sounds like the sort of thing that they will do, and probably much more efficiently than pure Python code. But as a simple example, if I have two coordinates written as tuples: p = (-3.265636, 0.198894, 0.090858) q = (-1.307161, 1.522212, 1.003463) I can write a Euclidean distance function like this: import math def distance(a, b): """Return the Euclidean distance between 3D points a and b.""" return math.sqrt( (a[0] - b[0])**2 + (a[1] - b[1])**2 + (a[2] - b[2])**2 ) and then call the function: result = distance(p, q) which will return 2.5337013913983633 and assign it to the variable "result". Does that help? -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor