Re: Regarding Python

2020-04-17 Thread Bev In TX


Bev

> On Apr 16, 2020, at 5:36 PM, Muneer Malla  wrote:
> ... potion snipped ...
> I need to install python 3.7 or above version, however the previously 
> installed version is python2.7
> I tried many commands 
> sudo apt-get install python3.8
> after running the command it fails 
What failed?  Did the apt-get command fail, or were you unable to run Python 
3.8?

> I removed pthon 2.7 
> but again when I run the command 
> Python --version 
> it again shows python 2.7
If it were me, I would not remove Python 2.7, as on some older Linux versions, 
it may still be used by the system.  Perhaps that’s why you were unable to get 
rid of it.

> please suggest the commands 
> I have my python version 3.8 downloaded in the download folder

Python 2 and Python 3 can happily coexist on the same Linux system.  If both 
are installed, running “python” will invoke version 2.x, while running 
“python3” will invoke version 3.x (without the quotes).  

If for some reason you must run Python 3 with the “python” command on systems 
with both Python 2 and 3, then set up a virtual environment and source into it 
before running Python 3.
https://docs.python.org/3/tutorial/venv.html
https://docs.python.org/3/library/venv.html?highlight=venv

Bev in TX


-- 
https://mail.python.org/mailman/listinfo/python-list


Floating point issue

2020-04-17 Thread Aakash Jana
I am calculating couple of ratios and according to the problem there must
be a 6 decimal precision. But when I print the result I only get one 0.
E.g:- 2 / 5 = 0.40 but I am only getting 0.4

On Fri, 17 Apr 2020, 4:08 am Muneer Malla  Dear All
> hope you all are fine and doing good in these critical conditions
> While I am need to Python
> And I a generally using it in running a software QIIME
> in virtual machine (Linux based).
> I need to install python 3.7 or above version, however the previously
> installed version is python2.7
> I tried many commands
> sudo apt-get install python3.8
> after running the command it fails
> I removed pthon 2.7
> but again when I run the command
> Python --version
> it again shows python 2.7
> please suggest the commands
> I have my python version 3.8 downloaded in the download folder
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Floating point problem

2020-04-17 Thread Aakash Jana
I am calculating couple of ratios and according to the problem there must
be a 6 decimal precision. But when I print the result I only get one 0.
E.g:- 2 / 5 = 0.40 but I am only getting 0.4
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-17 Thread Peter Otten
Aakash Jana wrote:

> I am calculating couple of ratios and according to the problem there must
> be a 6 decimal precision. But when I print the result I only get one 0.
> E.g:- 2 / 5 = 0.40 but I am only getting 0.4

Make sure that you are using Python 3, not Python 2 or use at least one 
float operand:

# Python 3
>>> 2/5
0.4

# Python 2 and 3
>>> 2.0 / 5
0.4

You can get the old default behaviour with the // operator:

# Python 3 (and Python 2)
>>> 2//5
0
>>> 7//2
3

If for some reason you cannot switch to Python 3 you can add the line

from __future__ import division

at the top of your script or module. Then:

$ python
Python 2.7.6 (default, Nov 13 2018, 12:45:42) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import division
>>> 2 / 5
0.4


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-17 Thread Aakash Jana
I am running python 3.8 only but my issue is I need more zeroes after my
result.
I want 2/5 = 0.40
But I am only getting 0.4

On Fri, 17 Apr 2020, 5:08 pm Peter Otten <[email protected] wrote:

> Aakash Jana wrote:
>
> > I am calculating couple of ratios and according to the problem there must
> > be a 6 decimal precision. But when I print the result I only get one 0.
> > E.g:- 2 / 5 = 0.40 but I am only getting 0.4
>
> Make sure that you are using Python 3, not Python 2 or use at least one
> float operand:
>
> # Python 3
> >>> 2/5
> 0.4
>
> # Python 2 and 3
> >>> 2.0 / 5
> 0.4
>
> You can get the old default behaviour with the // operator:
>
> # Python 3 (and Python 2)
> >>> 2//5
> 0
> >>> 7//2
> 3
>
> If for some reason you cannot switch to Python 3 you can add the line
>
> from __future__ import division
>
> at the top of your script or module. Then:
>
> $ python
> Python 2.7.6 (default, Nov 13 2018, 12:45:42)
> [GCC 4.8.4] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from __future__ import division
> >>> 2 / 5
> 0.4
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-17 Thread Rhodri James

On 17/04/2020 12:40, Aakash Jana wrote:

I am running python 3.8 only but my issue is I need more zeroes after my
result.
I want 2/5 = 0.40
But I am only getting 0.4


When you just print or display a floating point number, Python only uses 
as many digits as needed if the answer happens to be a (small enough) 
exact decimal [*].


>>> foo = 2/5
>>> print(foo)
0.4

If you want the number displayed differently, you have to format it 
yourself.


>>> print("{:6f}".format(foo))
0.40


[*]: Since floats are stored internally in the standard IEEE *binary* 
format, what constitutes an *exact* decimal may be a little surprising!


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-17 Thread Peter Otten
Aakash Jana wrote:

> I am running python 3.8 only but my issue is I need more zeroes after my
> result.
> I want 2/5 = 0.40
> But I am only getting 0.4

This is either a formatting problem

>>> value = 0.4
>>> print(f"{value:10.6f}")
  0.40

or -- if you want to *calculate* with a fixed precision -- the job for a 
specialist library:

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

-- 
https://mail.python.org/mailman/listinfo/python-list


Scientific Software Developers | Job positions at CMCC Foundation, Italy

2020-04-17 Thread CMCC Info

/Please, feel free to circulate //to anyone you think may be interested.///
--

Open positions at CMCC Foundation:

Scientific Software Developer (Job Opening Code: 10712) 


Deadline: 30/04/2020
The location is CMCC Headquarters in Lecce, LE, Italy.

The primary purposes for this position is to design and implement data 
science software libraries and applications for climate change. The 
activities will be carried out in the context of the Data Science (DS) 
research team of theAdvanced Scientific Computing Division (ASC) 
 
at CMCC. Other duties will be related contribution to participation to 
meetings, reporting, open source software communities.


Scientific Software Developer (Job Opening Code: 
10713) 


Deadline: 30/04/2020
The location is CMCC Headquarters in Lecce, LE, Italy*.*

The primary purposes for this position is to explore and develop 
Machine/Deep Learning techniques applied to climate change applications.
The activities will be carried out in the context of the Exascale and 
Machine Learning for Climate Change (EMLC2) research team of the 
Advanced Scientific Computing Division (ASC) 
 
at CMCC. Other duties will be related contribution to participation to 
project meetings, reporting, open source software communities.


For further information on CMCC Job Opportunities, please visit our 
website https://www.cmcc.it/work-with-us.


--

Fondazione Centro Euro-Mediterraneo sui Cambiamenti Climatici
Web: www.cmcc.it  - Contact us: [email protected] 



--
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-17 Thread ast

Le 17/04/2020 à 13:40, Aakash Jana a écrit :


I am running python 3.8 only but my issue is I need more zeroes after my
result.
I want 2/5 = 0.40
But I am only getting 0.4


f"{2/5:.6f}"
'0.40'

--
https://mail.python.org/mailman/listinfo/python-list


Tkinter date entry with boxes

2020-04-17 Thread annunci . pervendite
Hi, I'm creating a registration form and I found this script that I'd like to 
use to have my participants to input their birth date:

import tkinter as tk


class DateEntry(tk.Frame):
def __init__(self, parent, **kwargs):
years = kwargs.pop('years', (1900, ))
super().__init__(parent, **kwargs)

vcmd = (self.register(self._validate), '%W', '%V', '%v', '%P', '%S')

for name, text, v1, v2 in (('day', 'DD', 1, 31),
   ('month', 'MM', 1, 12),
   ('year', '', years[0], years[1])):
e = tk.Entry(self, name=name, width=len(text) + 1, justify="center")
e.pack(side=tk.LEFT)
e.insert(0, text)
e._valid = (len(text), v1, v2)
e.config(validate="all", validatecommand=vcmd)

def get(self):
data = {}
for entry in [self.nametowidget(child) for child in self.children]:
text = entry.get()
data[entry.winfo_name()] = int(text) if text.isdigit() else None
return data

def _validate(self, widget, cmd, validate, value, text):
# get this entry reference
w = self.nametowidget(widget)

# Clear entry or do nothing
if cmd in ('focusin', 'forced') or value == '':
if not value.isdigit():
w.delete(0, tk.END)
# Set the 'validate' option again after edit
w.after_idle(w.config, {'validate': validate})
return True

# process key
elif cmd == 'key' and value.isdigit():
# get from this entry the valid parameter
l, v1, v2 = w._valid

# get the startswith chars if 
if v1 > 1 and len(value) < l:
l2 = len(value)
v1, v2 = int(str(v1)[:l2]), int(str(v2)[:l2])

# allow leading zero in DD / MM
elif v1 == 1 and len(value) == 1 and int(value) == 0:
return True

# return True if all valid else False
return all((text.isdigit(), v1 <= int(value) <= v2, len(value) <= 
l))

# else return False
return False


And I'm using it like this: 

self.birthday = StringVar(self)
self.birthday.set('')
self.birthday=DateEntry(self, years=(1935, 2020))
self.birthday.place(relx=0.22, rely=0.16, height=25, width=100)


I'm having several issues and questions:
1. I'd like to write the complete entry date on excel but it gives me a format 
date error when I try to do so. Also when I try to print(self.birthday.get()) I 
get nothing. I can't access the value
2. I'd need the day, month and year also saved separately (I need the year to 
calculate the age of the participants).
3. Is it possible to put a little bit of space between the three boxes and add 
a "/" between them?
4. Lastly right now it is possible to input incorrect date like 31 November 
ecc. How could I fix this?
Thank you for your help!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter date entry with boxes

2020-04-17 Thread Souvik Dutta
You can use 12 if statements to check for the correctness of dates. For the
year you would only be needed to check the type. To insert "/" you should
return your own data type. That is make a class that returns a string of
the format "dd/mm/yy"
using parameters of date, month and year. As for not getting the value I
think your syntax is not correct. Are you sure it would not be .getText()
or something similar.

On Fri, 17 Apr, 2020, 7:55 pm ,  wrote:

> Hi, I'm creating a registration form and I found this script that I'd like
> to use to have my participants to input their birth date:
>
> import tkinter as tk
>
>
> class DateEntry(tk.Frame):
> def __init__(self, parent, **kwargs):
> years = kwargs.pop('years', (1900, ))
> super().__init__(parent, **kwargs)
>
> vcmd = (self.register(self._validate), '%W', '%V', '%v', '%P',
> '%S')
>
> for name, text, v1, v2 in (('day', 'DD', 1, 31),
>('month', 'MM', 1, 12),
>('year', '', years[0], years[1])):
> e = tk.Entry(self, name=name, width=len(text) + 1,
> justify="center")
> e.pack(side=tk.LEFT)
> e.insert(0, text)
> e._valid = (len(text), v1, v2)
> e.config(validate="all", validatecommand=vcmd)
>
> def get(self):
> data = {}
> for entry in [self.nametowidget(child) for child in self.children]:
> text = entry.get()
> data[entry.winfo_name()] = int(text) if text.isdigit() else
> None
> return data
>
> def _validate(self, widget, cmd, validate, value, text):
> # get this entry reference
> w = self.nametowidget(widget)
>
> # Clear entry or do nothing
> if cmd in ('focusin', 'forced') or value == '':
> if not value.isdigit():
> w.delete(0, tk.END)
> # Set the 'validate' option again after edit
> w.after_idle(w.config, {'validate': validate})
> return True
>
> # process key
> elif cmd == 'key' and value.isdigit():
> # get from this entry the valid parameter
> l, v1, v2 = w._valid
>
> # get the startswith chars if 
> if v1 > 1 and len(value) < l:
> l2 = len(value)
> v1, v2 = int(str(v1)[:l2]), int(str(v2)[:l2])
>
> # allow leading zero in DD / MM
> elif v1 == 1 and len(value) == 1 and int(value) == 0:
> return True
>
> # return True if all valid else False
> return all((text.isdigit(), v1 <= int(value) <= v2, len(value)
> <= l))
>
> # else return False
> return False
>
>
> And I'm using it like this:
>
> self.birthday = StringVar(self)
> self.birthday.set('')
> self.birthday=DateEntry(self, years=(1935, 2020))
> self.birthday.place(relx=0.22, rely=0.16, height=25, width=100)
>
>
> I'm having several issues and questions:
> 1. I'd like to write the complete entry date on excel but it gives me a
> format date error when I try to do so. Also when I try to
> print(self.birthday.get()) I get nothing. I can't access the value
> 2. I'd need the day, month and year also saved separately (I need the year
> to calculate the age of the participants).
> 3. Is it possible to put a little bit of space between the three boxes and
> add a "/" between them?
> 4. Lastly right now it is possible to input incorrect date like 31
> November ecc. How could I fix this?
> Thank you for your help!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread dcwhatthe
Yes,personal preference is definitely a factor and a bias, in these matters.

But aside from trying to make it easier for future A.I. to figure out what the 
heck we humans were doing, it also makes a difference in how the IDE interpets 
the code.

Maybe it isn't true for all IDE's or all languages. (I know SOMEONE will 
interject here, to argue for the sake of arguing). But when I worked with 
Groovy in Intellij about 5 years ago, there were times when the IDE was 
confused, during a debugging sessions. I don't remember the exact details, but 
that anomaly happened only with DEFed variables ; it didn't happen when the 
data type was specified.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point issue

2020-04-17 Thread Cousin Stanley
Aakash Jana wrote:

> I am calculating couple of ratios and according to the problem 
> there must be a 6 decimal precision. 
> 
> But when I print the result I only get one 0.
>
> E.g:- 2 / 5 = 0.40 but I am only getting 0.4

You might try using a  ' '.format  string 

ratios = { 
 '1/8'  :  1/8 , 
 '1/5'  :  1/5 ,  
 '1/4'  :  1/4 , 
 '1/3'  :  1/3 , 
 '2/5'  :  2/5 , 
 '5/9'  :  5/9 , 
 '2/3'  :  2/3 , 
 '4/5'  :  4/5 , 
 '7/8'  :  7/8 , 
 '9/5'  :  9/5 , 
 '22/7' :  22/7 }

print()
 
for fraction , ratio in ratios.items() : 

print( '  {:4s}  {:.6f} '.format( fraction , ratio ) )









-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread Rhodri James

On 17/04/2020 17:18, [email protected] wrote:

Maybe it isn't true for all IDE's or all languages. (I know SOMEONE
will interject here, to argue for the sake of arguing). But when I
worked with Groovy in Intellij about 5 years ago, there were times
when the IDE was confused, during a debugging sessions. I don't
remember the exact details, but that anomaly happened only with DEFed
variables ; it didn't happen when the data type was specified.


This is a general problem for IDEs, and type information isn't always 
helpful.  The number of times I have had to add useless bits of code to 
cast something to (uint8_t *) because I want to see the bytes and the 
IDE will not give up on trying to interpret them for me.


And people wonder why I stick to gdb when at all possible :-)

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Why generate POP_TOP after an "import from?"

2020-04-17 Thread Adam Preble
Given this in Python 3.6.8:

from dis import dis

def import_from_test():
   from sys import path

>>> dis(import_from_test)
  2   0 LOAD_CONST   1 (0)
  2 LOAD_CONST   2 (('path',))
  4 IMPORT_NAME  0 (sys)
  6 IMPORT_FROM  1 (path)
  8 STORE_FAST   0 (path)
 10 POP_TOP
 12 LOAD_CONST   0 (None)
 14 RETURN_VALUE

I don't understand why there's a POP_TOP there that I don't get for an 
import_name grammatical statement.

IMPORT_NAME needs to eat the top two entries of the stack for level and the 
from-list. BTW I don't know what level is for either since my science projects 
have always had it be zero, but that's another question.

IMPORT_NAME will the push the module on to the stack.

IMPORT_FROM will import path from the module on the stack, and push that result 
on the stack.

STORE_FAST will store path for use, finally "modifying the namespace."

At this point, my conceptual stack is empty. If I POP_TOP then I have nothing 
to pop and the world would end. Yet, it doesn't. What am I missing?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why generate POP_TOP after an "import from?"

2020-04-17 Thread Adam Preble
On Friday, April 17, 2020 at 1:22:18 PM UTC-5, Adam Preble wrote:

> At this point, my conceptual stack is empty. If I POP_TOP then I have nothing 
> to pop and the world would end. Yet, it doesn't. What am I missing?

Check out this guy replying to himself 10 minutes later.

I guess IMPORT_FROM pushes the module back on to the stack afterwards so that 
multiple import-from's can be executed off of it. This is then terminated with 
a POP_TOP:

>>> def import_from_multi():
... from sys import path, bar
...
>>> dis(import_from_multi)
  2   0 LOAD_CONST   1 (0)
  2 LOAD_CONST   2 (('path', 'bar'))
  4 IMPORT_NAME  0 (sys)
  6 IMPORT_FROM  1 (path)
  8 STORE_FAST   0 (path)
 10 IMPORT_FROM  2 (bar)
 12 STORE_FAST   1 (bar)
 14 POP_TOP
 16 LOAD_CONST   0 (None)
 18 RETURN_VALUE
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why generate POP_TOP after an "import from?"

2020-04-17 Thread Chris Angelico
On Sat, Apr 18, 2020 at 4:26 AM Adam Preble  wrote:
>
> Given this in Python 3.6.8:
>
> from dis import dis
>
> def import_from_test():
>from sys import path
>
> >>> dis(import_from_test)
>   2   0 LOAD_CONST   1 (0)
>   2 LOAD_CONST   2 (('path',))
>   4 IMPORT_NAME  0 (sys)
>   6 IMPORT_FROM  1 (path)
>   8 STORE_FAST   0 (path)
>  10 POP_TOP
>  12 LOAD_CONST   0 (None)
>  14 RETURN_VALUE
>
> I don't understand why there's a POP_TOP there that I don't get for an 
> import_name grammatical statement.
>
> IMPORT_NAME needs to eat the top two entries of the stack for level and the 
> from-list. BTW I don't know what level is for either since my science 
> projects have always had it be zero, but that's another question.
>
> IMPORT_NAME will the push the module on to the stack.
>
> IMPORT_FROM will import path from the module on the stack, and push that 
> result on the stack.
>
> STORE_FAST will store path for use, finally "modifying the namespace."
>
> At this point, my conceptual stack is empty. If I POP_TOP then I have nothing 
> to pop and the world would end. Yet, it doesn't. What am I missing?
>

Good question, and nicely put, thank you. I like questions like this :)

Here's another function that can showcase a bit more of what's going on:

>>> def f():
... from . import foo, bar, baz
...
>>> dis.dis(f)
  2   0 LOAD_CONST   1 (1)
  2 LOAD_CONST   2 (('foo', 'bar', 'baz'))
  4 IMPORT_NAME  0
  6 IMPORT_FROM  1 (foo)
  8 STORE_FAST   0 (foo)
 10 IMPORT_FROM  2 (bar)
 12 STORE_FAST   1 (bar)
 14 IMPORT_FROM  3 (baz)
 16 STORE_FAST   2 (baz)
 18 POP_TOP
 20 LOAD_CONST   0 (None)
 22 RETURN_VALUE

The level is used for package-relative imports, and will basically be
the number of leading dots (eg "from ...spam import x" will have a
level of 3). You're absolutely right with your analysis, with one
small clarification:

> IMPORT_FROM will import path from the module on the stack, and push that 
> result on the stack.
>

It leaves the module on the stack, allowing chained IMPORT_FROM
operations to grab multiples from the same module. That's why it needs
to be popped off at the end.

In theory, I suppose, you could replace the POP_TOP with a STORE_FAST
into "sys", and thus get a two-way import that both grabs the module
and also grabs something out of it. Not very often wanted, but could
be done if you fiddle with the bytecode.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why generate POP_TOP after an "import from?"

2020-04-17 Thread Alexandre Brault

On 2020-04-17 2:22 p.m., Adam Preble wrote:

Given this in Python 3.6.8:

from dis import dis

def import_from_test():
from sys import path


dis(import_from_test)

   2   0 LOAD_CONST   1 (0)
   2 LOAD_CONST   2 (('path',))
   4 IMPORT_NAME  0 (sys)
   6 IMPORT_FROM  1 (path)
   8 STORE_FAST   0 (path)
  10 POP_TOP
  12 LOAD_CONST   0 (None)
  14 RETURN_VALUE

I don't understand why there's a POP_TOP there that I don't get for an 
import_name grammatical statement.

IMPORT_NAME needs to eat the top two entries of the stack for level and the 
from-list. BTW I don't know what level is for either since my science projects 
have always had it be zero, but that's another question.

IMPORT_NAME will the push the module on to the stack.

IMPORT_FROM will import path from the module on the stack, and push that result 
on the stack.

STORE_FAST will store path for use, finally "modifying the namespace."

At this point, my conceptual stack is empty. If I POP_TOP then I have nothing 
to pop and the world would end. Yet, it doesn't. What am I missing?


You can get an idea of what you're missing if you import multiple names 
from a module at once:


>>> def f():
...     from sys import path, argv
...
>>> dis.dis(f)
  2   0 LOAD_CONST   1 (0)
  2 LOAD_CONST   2 (('path', 'argv'))
  4 IMPORT_NAME  0 (sys)
  6 IMPORT_FROM  1 (path)
  8 STORE_FAST   0 (path)
 10 IMPORT_FROM  2 (argv)
 12 STORE_FAST   1 (argv)
 14 POP_TOP
 16 LOAD_CONST   0 (None)
 18 RETURN_VALUE

As shown here (and confirmed by the doc of the IMPORT_FROM opcode), 
IMPORT_FROM loads an attribute from the module on top of the stack, but 
doesn't pop the module. The POP_TOP instruction is what does.


--
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread dcwhatthe
On Friday, April 17, 2020 at 2:11:17 PM UTC-4, Rhodri James wrote:
> On 17/04/2020 17:18, dc wrote:
> > Maybe it isn't true for all IDE's or all languages. (I know SOMEONE
> > will interject here, to argue for the sake of arguing). But when I
> > worked with Groovy in Intellij about 5 years ago, there were times
> > when the IDE was confused, during a debugging sessions. I don't
> > remember the exact details, but that anomaly happened only with DEFed
> > variables ; it didn't happen when the data type was specified.
> 
> This is a general problem for IDEs, and type information isn't always 
> helpful.  The number of times I have had to add useless bits of code to 
> cast something to (uint8_t *) because I want to see the bytes and the 
> IDE will not give up on trying to interpret them for me.
> 
> And people wonder why I stick to gdb when at all possible :-)
> 
> -- 
> Rhodri James *-* Kynesim Ltd

Never worked with it.  Is it a debugger for compiled code, i.e. it steps 
through the executable while displaying the source?  Or interpreted code?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread Rhodri James

On 17/04/2020 22:27, [email protected] wrote:

On Friday, April 17, 2020 at 2:11:17 PM UTC-4, Rhodri James wrote:

And people wonder why I stick to gdb when at all possible :-)

Never worked with it.  Is it a debugger for compiled code, i.e. it steps 
through the executable while displaying the source?  Or interpreted code?


The GNU project debugger has been around for quite a few decades now. 
It's a debugger for compiled code, covering about a dozen source 
languages (I can't be bothered to count at this time of night).  It is 
ridiculously flexible, command-line driven, and most importantly it does 
what you tell it to do.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


python read line by line and keep indent

2020-04-17 Thread hnasr9999
Hi;

I am reading a Python file and find an specific line, replace a text and then 
write back to the file.

When I check back the file, I am getting indent error.

How to fix this issue.

reading_file = open("myfile.py", "r") 
new_file_content = ""
for line in reading_file:
stripped_line = line.strip()
#print (stripped_line)
if (stripped_line.find('siteip = ') != -1):
stripped_line = "siteip = \"%s\"" %(siteip)
new_line = stripped_line
new_file_content += new_line +"\n"
reading_file.close()
writing_file = open("myfile", "w")
writing_file.write(new_file_content)
writing_file.close()

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread DL Neil via Python-list

On 18/04/20 4:18 AM, [email protected] wrote:

Yes,personal preference is definitely a factor and a bias, in these matters.

But aside from trying to make it easier for future A.I. to figure out what the 
heck we humans were doing, it also makes a difference in how the IDE interpets 
the code.

Maybe it isn't true for all IDE's or all languages. (I know SOMEONE will 
interject here, to argue for the sake of arguing). But when I worked with 
Groovy in Intellij about 5 years ago, there were times when the IDE was 
confused, during a debugging sessions. I don't remember the exact details, but 
that anomaly happened only with DEFed variables ; it didn't happen when the 
data type was specified.



I am going to interject here - and because there is arguing!

1 the above description seems to suggest that the coder's objectives are 
now to be split: firstly to make Python understand his/her instruction, 
and secondly to ensure that the IDE knows what's going-on.


Does the IDE serve you, or do you serve the tool?
- collaboration notwithstanding
- similarly, without considering UX (users what users?), etc!


2 AI's creative processes may initially, in a macro sense, be modeled on 
human cognition; but when it comes to operation, their methodologies are 
quite different. Why would a computer, programming a(nother) computer, 
use a language/tool developed for human-computer communication?



3 The core-point seems to be, that without increased detail in the 
Python code, an IDE or AI will have difficulty understanding (my/our) 
human-intent. This is a feature/failing* of all "communication" (a 
component of "transmission" and/or "noise").


For example, please review the original post. Can you show me where it 
even hints that a response should consider anything other than *human* 
understanding? (ie your own)


* 'trickery' aside, how many students/trainees have you heard utter 
phrases such as, "you didn't tell [me|us] that"?



4 As previously mentioned: [typing, hints, PEP, Python, ...]. If you'd 
care to build a tool which makes use of typing, that is the current 
philosophy/invitation (per earlier comment and refs). Pending such a 
tool, should we (all) start writing Python-with-typing in the 
expectation of the requirements of some future hopes, or 'vapor-ware'? 
(see also mypy)



5 I like the idea (any idea) of something that will make (my) life 
easier (I've had to work very hard to be this lazy!). Thus, a tool (IDE 
or whatever) that will do 'stuff' for me, or save me time, eg by saving 
me from my own coding-mistakes; is bound to attract my attention. 
Similarly: speed of coding, improved readability for others, ...


One of the joys of Python is "for". We (still) tend to call it a 
"for...loop", but to be correct it should be something like a 
"for-all...loop"! The traditional for...loop goes right back to early 
"high-level programming languages", eg FORTRAN's DO-loop. The reason 
Python has its (different) approach is because so many 
programming-errors relate to "pointers" and their oft-related 
"out-by-one errors", ie


for pointer from 1 to 10# this is NOT Python!
print( array[ pointer ], array[ pointer } ^ 2 )

What if the "1" or the "10" is a variable, and the programmer fails to 
keep them related/limited to the size of the array? What if the array 
was populated from a zero-th element? ...


Instead, Python says:

for element in listNM:
print( ...

Easy - doesn't matter how long/short the list may be!

What's the point here (for you)?

Much analysis has been performed on programming, algorithms, code 
structures, the psychology of computer programming, etc. Certainly, our 
BDEVIL did when designing Python! Rather than (apparently!) starting at 
the syntactic-level (with data-typing), might your research benefit from 
looking at such meta-observations, and working from there? .


Alternately, perhaps Python does not lend itself to this sort of 
research? Might another programming language might be a better choice? 
The designers of the Rust programming language appeared to take a quite 
different approach from Guido Van Rossum. A (rather shabby) comparison 
between the two languages shows one taking the line 'we are all adults 
here', but the other attempts to be 'secure' (in several definitions of 
the word).



Web.Refs:
http://mypy-lang.org/
https://www.python.org/dev/peps/pep-0401/
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: python read line by line and keep indent

2020-04-17 Thread Greg Ewing

On 18/04/20 11:10 am, [email protected] wrote:

Hi;

I am reading a Python file and find an specific line, replace a text and then 
write back to the file.

When I check back the file, I am getting indent error.


It looks like your script is stripping out all the indentation when
it writes the lines back. Indentation is syntactically significant
in Python, so you need to preserve it.

My suggestions:

1. Don't strip the lines.

2. When you find the 'siteip = ' line, instead of constructing
a whole new line, replace the part after '=' with the new siteip,
so that you keep whatever indentation the line had before.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: python read line by line and keep indent

2020-04-17 Thread DL Neil via Python-list

On 18/04/20 11:10 AM, [email protected] wrote:

I am reading a Python file and find an specific line, replace a text and then 
write back to the file.

When I check back the file, I am getting indent error.

How to fix this issue.



Please make it easier for us (volunteers giving-up our free time) to 
help you...


Please provide a copy-paste of the error message.

Please indicate which is the pertinent line of code.

Please consider if it would help to provide sample data (in and out)
- lines of text that have worked
- the line/lines that fail
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: python read line by line and keep indent

2020-04-17 Thread Souvik Dutta
You can actually read and write in a file simultaneously. Just replace "r"
with "w+" if the file has not been previously made or use "r+" is the file
has already been made.

Souvik flutter dev

On Sat, Apr 18, 2020, 4:45 AM  wrote:

> Hi;
>
> I am reading a Python file and find an specific line, replace a text and
> then write back to the file.
>
> When I check back the file, I am getting indent error.
>
> How to fix this issue.
>
> reading_file = open("myfile.py", "r")
> new_file_content = ""
> for line in reading_file:
> stripped_line = line.strip()
> #print (stripped_line)
> if (stripped_line.find('siteip = ') != -1):
> stripped_line = "siteip = \"%s\"" %(siteip)
> new_line = stripped_line
> new_file_content += new_line +"\n"
> reading_file.close()
> writing_file = open("myfile", "w")
> writing_file.write(new_file_content)
> writing_file.close()
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list