empty stdout (subprocess.run)

2022-01-19 Thread James Smith
I'm trying to run a shell command but the stdout is empty:

import subprocess

torrentno=8
cmd="/usr/bin/transmission-remote --torrent %s --info", str(torrentno)
res=subprocess.run(cmd, shell=True, check=True, universal_newlines=True, 
capture_output=True)
print(res)

CompletedProcess(args=('/usr/bin/transmission-remote --torrent %s --info', 
'1'), returncode=0, stdout='', stderr='')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: empty stdout (subprocess.run)

2022-01-20 Thread James Smith
On Wednesday, January 19, 2022 at 11:08:58 PM UTC-5, Dennis Lee Bieber wrote:

> Don't you need to provide for that %s? Perhaps 
> 
> cmd="/usr/bin/transmission-remote --torrent %s --info" % torrentno 

That works, thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: empty stdout (subprocess.run)

2022-01-20 Thread James Smith
On Wednesday, January 19, 2022 at 11:14:28 PM UTC-5, cameron...@gmail.com wrote:

> But I recommend you use shell=False and make: 
> 
> cmd = ["/usr/bin/transmission-remote", "--torrent", str(torrentno), "--info"] 

I like that. :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


=+ for strings

2020-05-03 Thread James Smith
I tried:
dt=+"{:02d}".format(day)
but I got:
dt=+"{:02d}".format(day)
TypeError: bad operand type for unary +: 'str'

This works:
dt=dt+"{:02d}".format(day)

Why can't I do the shortcut on strings?
-- 
https://mail.python.org/mailman/listinfo/python-list


pickle and then object changes

2015-01-20 Thread James Smith
Say an object like this exists:
class test:
a = ""
b = ""

You pickle it.

You change the object definition to have a new field:
class test
a = ""
b = ""
c = ""

You read the pickled object.
Will it load but ignore the new field?
That is what I want.
-- 
https://mail.python.org/mailman/listinfo/python-list


regex line by line over file

2014-03-26 Thread James Smith
I can't get this to work.
It runs but there is no output when I try it on a file.


#!/usr/bin/python

import os
import sys
import re
from datetime import datetime

#logDir = '/nfs/projects/equinox/platformTools/RTLG/RTLG_logs';
#os.chdir( logDir );

programName = sys.argv[0]
fileName = sys.argv[1]

#pattern = re.compile('\s*\\"SHELF-.*,SC,.*,:\\"Log Collection In Progress\\"')
re.M
p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"')
l = '"SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In 
Progress\",NONE:170035-6364-1048,:YEAR=2014,MODE=NONE"'

# this works :-)
m = p.match( l )
if m:
print( l )

# this doesn't match anything (or the if doesn't work) :-(
with open(fileName) as f:
for line in f:
# debug code (print the line without adding a linefeed)
# sys.stdout.write( line )
if p.match(line):
print(line)


The test file just has one line:
"SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In 
Progress\",NONE:170035-6364-1048,:YEAR=2014,MODE=NONE"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex line by line over file

2014-03-26 Thread James Smith
On Wednesday, March 26, 2014 11:23:29 PM UTC-4, James Smith wrote:
> I can't get this to work.
> 
> It runs but there is no output when I try it on a file.
> 
> 
> 
> 
> 
> #!/usr/bin/python
> 
> 
> 
> import os
> 
> import sys
> 
> import re
> 
> from datetime import datetime
> 
> 
> 
> #logDir = '/nfs/projects/equinox/platformTools/RTLG/RTLG_logs';
> 
> #os.chdir( logDir );
> 
> 
> 
> programName = sys.argv[0]
> 
> fileName = sys.argv[1]
> 
> 
> 
> #pattern = re.compile('\s*\\"SHELF-.*,SC,.*,:\\"Log Collection In 
> Progress\\"')
> 
> re.M
> 
> p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"')
> 
> l = '"SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection 
> In Progress\",NONE:170035-6364-1048,:YEAR=2014,MODE=NONE"'
> 
> 
> 
> # this works :-)
> 
> m = p.match( l )
> 
> if m:
> 
> print( l )
> 
> 
> 
> # this doesn't match anything (or the if doesn't work) :-(
> 
> with open(fileName) as f:
> 
> for line in f:
> 
> # debug code (print the line without adding a linefeed)
> 
> # sys.stdout.write( line )
> 
> if p.match(line):
> 
> print(line)
> 
> 
> 
> 
> 
> The test file just has one line:
> 
> "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In 
> Progress\",NONE:170035-6364-1048,:YEAR=2014,MODE=NONE"

I tried the re.M in the compile and that didn't help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex line by line over file

2014-03-27 Thread James Smith
On Thursday, March 27, 2014 1:32:03 AM UTC-4, Steven D'Aprano wrote:

> - are you mistaken about the content of the file?
> 
> I can't help you with the first. But the second: try running this:
> 
> # line2 and pat as defined above
> filename = sys.argv[1]
> with open(filename) as f:
> for line in f:
> print(len(line), line==line2, repr(line))
> print(repr(pat.match(line)))
> 
> which will show you what you have and whether or not it matches 
> what you think it has. I expect that the file contents is not what 
> you think it is, because the regex is matching the sample line.
> 
> Good luck!
> 
> -- 
> 
> Steven

It should match this:
(134, False, '\'   "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:"Log 
Collection In 
Progress",NONE:170035-6364-1048,:YEAR=2014,MODE=NONE"\\r\\n\'')

Is the \r\n on the end of the line screwing it up?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex line by line over file

2014-03-27 Thread James Smith
On Thursday, March 27, 2014 9:41:55 AM UTC-4, James Smith wrote:

> (134, False, '\'   
> "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:"Log Collection In 
> Progress",NONE:170035-6364-1048,:YEAR=2014,MODE=NONE"\\r\\n\'')
> 
> 
> 
> Is the \r\n on the end of the line screwing it up?

Got it.
I needed an extra \ where I had 3 in the compile.
It's kinda weird it didn't need the extra \ when I ran it manually from the 
shell.
-- 
https://mail.python.org/mailman/listinfo/python-list


help with regex

2014-10-07 Thread James Smith
I want the last "1"
I can't this to work:

>>> pattern=re.compile( "(\d+)$" )
>>> match=pattern.match( "LINE: 235 : Primary Shelf Number (attempt 1): 1")
>>> print match.group()
-- 
https://mail.python.org/mailman/listinfo/python-list