On 12/02/2013 17:43, Marcin Mleczko wrote:
Hello,
given this kind of string:
"start SomeArbitraryAmountOfText start AnotherArbitraryAmountOfText end"
a search string like: r"start.*?end" would give me the entire string
from the first "start" to "end" : "start SomeArbitraryAmountOfText start
An
Marcin Mleczko wrote:
> given this kind of string:
>
> "start SomeArbitraryAmountOfText start AnotherArbitraryAmountOfText end"
>
> a search string like: r"start.*?end" would give me the entire string
> from the first "start" to "end" : "start SomeArbitraryAmountOfText start
> AnotherArbitraryAm
On 12/02/13 17:43, Marcin Mleczko wrote:
but I am interested only in the second part between the 2nd "start" and
the "end": "start AnotherArbitraryAmountOfText end"
What would be best, most clever way to search for that?
best and clever are not always the same.
The simplest way if its a fixe
Hello,
given this kind of string:
"start SomeArbitraryAmountOfText start AnotherArbitraryAmountOfText end"
a search string like: r"start.*?end" would give me the entire string
from the first "start" to "end" : "start SomeArbitraryAmountOfText start
AnotherArbitraryAmountOfText end"
but I am int
> for line in open(r'e:\pycode\out_test.txt','rb') :
>output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
> 16))) % ord(s.group()), line))
>
> This generated the traceback:
>
> File "E:\pycode\sample_decode_file_specials_from_hex.py", line 8
>output.write( re.sub(r'([^\w\s])', l
On Thu, 25 May 2006, Kent Johnson wrote:
> Yes, this is a feature of print, it always inserts a newline.
Well, you can get rid of the newline by ending with a comma, but it still
will insert spaces:
>>> for ch in "abc":
... print ch
...
a
b
c
>>> for ch in "abc":
... print ch,
...
a b c
>>>
On Thu, 25 May 2006, Alan Gauld wrote:
> In general I prefer to use string formatting to convert into hex
> format.
I'm a big fan of hexlify:
>>> from binascii import hexlify
>>> s="abc-123"
>>> hexlify(s)
'6162632d313233'
___
Tutor maillist - Tu
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Everyone,
Thanks for all of your patience on this.
I finally got it to work.
Here is the completed test code showing what is going on.
Not cleaned up yet but it works for proof-of-concept purposes.
#!/usr/bin/python
import re,base64
# Eva
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Kent,
Sorry for causing so much trouble.
I am not married to either a single or multi-line solution one way or
another.
Just a solution that works.
Based on something by Danny Yoo provided, I had started with something like:
import re,base6
Andrew Robert wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> When I alter the code to:
>
> import re,sys
>
> output = open(r'e:\pycode\new_test.txt','wb')
>
> for line in open(r'e:\pycode\out_test.txt','rb') :
>output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
lol..
Glutton for punishment I guess.
I tried removing the last parentheses but I then get an error that two
arguments are passed when three are expected.
Danny Yoo wrote:
>
>
>> for line in open(r'e:\pycode\out_test.txt','rb') :
>>output.w
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
When I alter the code to:
import re,sys
output = open(r'e:\pycode\new_test.txt','wb')
for line in open(r'e:\pycode\out_test.txt','rb') :
output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16)))
, line)
output.close()
I get the trac
> for line in open(r'e:\pycode\out_test.txt','rb') :
>output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
> 16))) % ord(s.group()), line))
Let's add some whitespace.
output.write(re.sub(r'([^\w\s])',
lambda s: chr(
Andrew Robert wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Hi all,
>
> I tried:
>
>
> output = open(r'e:\pycode\new_test.txt','wb')
>
> for line in open(r'e:\pycode\out_test.txt','rb') :
> output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
> 16))) % ord(s.group
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi all,
I tried:
output = open(r'e:\pycode\new_test.txt','wb')
for line in open(r'e:\pycode\out_test.txt','rb') :
output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(),
16))) % ord(s.group()), line))
This generated the traceback:
Fi
Andrew Robert wrote:
> Taking this a little further along, I wrote the converted file to a new
> file using:
>
>
> import re,sys
>
> output = open(r'e:\pycode\out_test.txt','wb')
>
> for line in open(r'e:\pycode\sigh.txt','rb') :
> output.write( re.sub(r'([^\w\s])', lambda s: '%%%2X' %
> or
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Great!
Taking this a little further along, I wrote the converted file to a new
file using:
import re,sys
output = open(r'e:\pycode\out_test.txt','wb')
for line in open(r'e:\pycode\sigh.txt','rb') :
output.write( re.sub(r'([^\w\s])', lambda s:
Andrew Robert wrote:
> The python method inserts extra blank lines after each hex value line.
> Does anyone know why this might be?
>
> Is the print statement inserting a artificial new line character?
Yes, this is a feature of print, it always inserts a newline. To avoid
this, use sys.stdout.wr
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Everyone
I did a comparison of the output between the perl and python methodology.
They do basically the same thing but the perl form seems to be more "true"
The python method inserts extra blank lines after each hex value line.
For example:
O
> Your code put me right on track.
>
> - From that point, I crafted the following code.
>
> What is confusing is how to take the captured character and
> transform it
> into a 3 digit hex value.
In general I prefer to use string formatting to convert into hex
format.
print "%3X% % myValue
you
> a = open(r'e:\pycode\csums.txt','rb').readlines()
>
> for line in a:
>print re.sub(r'([^\w\s])', lambda s: '%%%2X' % ord(s.group()),
> line)
Or just
for line in open(r'e:\pycode\csums.txt','rb'):
print.
> Breaking down the command, you appear to be calling an un-named
> function
>
Andrew Robert wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Wow!!..
>
> That awesome!
>
>
> My goal was not to make it a one-liner per-se..
>
> I was simply trying to show the functionality I was trying to duplicate.
>
> Boiling your one-liner down into a multi-line piece of co
[forwarding to tutor, although it looks like Andrew's making some good
headway from other messages]
-- Forwarded message --
Date: Wed, 24 May 2006 14:59:43 -0400
From: Andrew Robert <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Qu
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Wow!!..
That awesome!
My goal was not to make it a one-liner per-se..
I was simply trying to show the functionality I was trying to duplicate.
Boiling your one-liner down into a multi-line piece of code, I did:
#!c:\python24\python
import re,sys
On 24 Mai 2006, [EMAIL PROTECTED] wrote:
> I have two Perl expressions
>
>
> If windows:
>
> perl -ple "s/([^\w\s])/sprintf(q#%%%2X#, ord $1)/ge" somefile.txt
>
> If posix
>
> perl -ple 's/([^\w\s])/sprintf("%%%2X", ord $1)/ge' somefile.txt
>
>
>
> The [^\w\s] is a negated expression stating th
> perl -ple "s/([^\w\s])/sprintf(q#%%%2X#, ord $1)/ge" somefile.txt
Hi Andrew,
Give me a second. I'm trying to understand the command line switches:
(Looking in 'perl --help'...)
-p assume loop like -n but print line also, like sed
-l[octal] enable line ending proce
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Everyone,
I have two Perl expressions
If windows:
perl -ple "s/([^\w\s])/sprintf(q#%%%2X#, ord $1)/ge" somefile.txt
If posix
perl -ple 's/([^\w\s])/sprintf("%%%2X", ord $1)/ge' somefile.txt
The [^\w\s] is a negated expression stating th
27 matches
Mail list logo