Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Peter Otten
Albert-Jan Roskam wrote: > I was thinking it would also be possible to do (in Windows): > import os.path > os.path.sep = '/' > os.path.normpath('c:\\beeh/foo\\bar/baz') > > But alas, this still creates normalized windows-style paths. If your input data has only forward slashes you can keep it th

Re: [Tutor] Displaying Status on the Command Line

2018-11-08 Thread Zachary Ware
On Thu, Nov 8, 2018 at 10:10 AM Steven D'Aprano wrote: > Sorry, I don't understand that. Maybe its too early in the morning for > my brain, but given that you've imported the Python 3 print function > from the __future__ why do you need the customer wrapper? > > from __future__ import print_functi

Re: [Tutor] Displaying Status on the Command Line

2018-11-08 Thread Steven D'Aprano
On Thu, Nov 08, 2018 at 09:36:53AM -0600, Zachary Ware wrote: > You can use any of the `print` function tricks above in Python 2 with > the following boilerplate: > > from __future__ import print_function > > import sys > > _orig_print = print > > def print(*args, **kwargs): > flush = kwar

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Albert-Jan Roskam
From: Tutor on behalf of Alan Gauld via Tutor Sent: Thursday, November 8, 2018 10:49 AM To: tutor@python.org Subject: Re: [Tutor] Regex for Filesystem path (Asad) On 08/11/2018 02:55, Asad wrote: > Why is it putting \ this breaks the unix path it should be: > > /a/b/c/d/test/2

Re: [Tutor] Displaying Status on the Command Line

2018-11-08 Thread Zachary Ware
On Thu, Nov 8, 2018 at 4:12 AM Chip Wachob wrote: > I should have mentioned that I'm working with Python 2, but I think I > can parse my way through these examples. You can use any of the `print` function tricks above in Python 2 with the following boilerplate: from __future__ import print_funct

Re: [Tutor] best way to dynamically set class variables?

2018-11-08 Thread srinivasan
Once again thanks a lot guys for all your help and I really appreciate it that I can really come back to you, if am stuck with any python issues, as i was really a embedded linux platform developer >From now I have learnt not to use much bash commands with pipe and to just use the bash command and

Re: [Tutor] best way to dynamically set class variables?

2018-11-08 Thread Alan Gauld via Tutor
On 08/11/2018 07:46, Peter Otten wrote: > By the way I don't think exec() is bad as long as you control its input and > as long as this input is fairly simple. Yes, but reading arbitrary column names from a database is not exactly controlled input... -- Alan G Author of the Learn to Program w

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Alan Gauld via Tutor
On 08/11/2018 02:55, Asad wrote: > Why is it putting \ this breaks the unix path it should be: > > /a/b/c/d/test/28163133/22326541 ===> for unix platform logs > > \a\b\c\d\test\28163133\22326541 ===> for windows platform logs os.path.join uses the separator that is correct for your OS. Sinc

Re: [Tutor] Displaying Status on the Command Line

2018-11-08 Thread Alan Gauld via Tutor
On 08/11/2018 04:06, Chip Wachob wrote: > I should have mentioned that I'm working with Python 2, but I think I > can parse my way through these examples. OK, In that case you may want to investigate the sys.stdout approach. Just remember it's a pre opened file and use the write() method. But it

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-08 Thread Steven D'Aprano
On Wed, Nov 07, 2018 at 09:34:43PM -0500, Avi Gross wrote: > It is easier to understand code when it is shown unaltered. The character > "*" (as in asterisk) has plenty of meaning in many languages and especially > in python. > > WHY is it being shown in your snippet at beginning and end? As far

Re: [Tutor] best way to dynamically set class variables?

2018-11-08 Thread Avi Gross
I have been reading the replies and wonder sometimes if we understand the real question as intended. Classes in Python can be changed in all kinds of ways even after they have been defined and the changes take effect on any new instances created afterward. So can instances in multiple ways. If you

Re: [Tutor] Displaying Status on the Command Line

2018-11-08 Thread Chip Wachob
Wow! Thank you! Lots of things for me to try. I should have mentioned that I'm working with Python 2, but I think I can parse my way through these examples. Best, On 11/7/18, Cameron Simpson wrote: > On 08Nov2018 10:00, Steven D'Aprano wrote: >>> Note that I need this to be platform agnostic

Re: [Tutor] Displaying Status on the Command Line

2018-11-08 Thread Avi Gross
What Alan wrote makes sense if you just want to put out one mark per second till you stop. But if you want a percentage of progress, you need some way to estimate what percent of the way you are to being done. You need to determine how many marks represent 100% such as 50 periods. You need to have

Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-08 Thread Avi Gross
It is easier to understand code when it is shown unaltered. The character "*" (as in asterisk) has plenty of meaning in many languages and especially in python. WHY is it being shown in your snippet at beginning and end? *"cmd = "blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3" % fs"*, Is

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Asad
Hi All , Thanks it works for me . However the other issue is : testdir = dirname(dirname("/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log")) /a/b/c/d/test dirpath = join(testdir, '28163133/22326541') print dirpath /a/b/c/d/test\28163133/22326541 * Why is it putting \ this