In Python, dictionaries can have any hashable value as a string. In
particular I can say
d = {}
d[(1,2)] = "Right"
d["(1,2)"] = "Wrong"
d["key"] = "test"
In order to print "test" using % substitution I can say
print "%(key)s&q
Hello all,
I've been using Ansys which is a commercial FEA package which can be
controlled through its own scripting language they call APDL. Now I'm
trying to write some stand alone code in Python to supplement my current
efforts.
In Ansys I can do something like this.
*do,n,1,3
uot;Right"
> d["(1,2)"] = "Wrong"
> d["key"] = "test"
>
> In order to print "test" using % substitution I can say
>
> print "%(key)s" % d
Yes, because the dictionary has a key which is the string "key".
>
"Murali" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> In Python, dictionaries can have any hashable value as a string. In
> particular I can say
>
> d = {}
> d[(1,2)] = "Right"
> d["(1,2)"] = "Wrong"
> d["ke
On 26 Jan 2006 15:40:47 -0800, "Murali" <[EMAIL PROTECTED]> wrote:
>In Python, dictionaries can have any hashable value as a string. In
>particular I can say
>
>d = {}
>d[(1,2)] = "Right"
>d["(1,2)"] = "Wrong"
>d["key"]
No. I dont have a real life example. I was explaining % substitution to
somebody and realized that I have only used it in the form where the
keys are strings. Was wondering if there is some special syntax already
part of python with which I can lookup the dictionary using a tuple as
a key
On Fri, 27 Jan 2006 15:54:30 -0800, Murali wrote:
> No. I dont have a real life example. I was explaining % substitution to
> somebody and realized that I have only used it in the form where the
> keys are strings. Was wondering if there is some special syntax already
> part of pytho
"John Bausano" <[EMAIL PROTECTED]> wrote:
>
>Hello all,
>
>I've been using Ansys which is a commercial FEA package which can be
>controlled through its own scripting language they call APDL. Now I'm
>trying to write some stand alone code in Python to supplement my current
>efforts.
>
>In Ansys
On Mon, 26 Sep 2005 21:09:51 -0400, "John Bausano" <[EMAIL PROTECTED]> wrote:
>Hello all,
...
Funny enough, some people have wanted to substitute a more dynamic character
for me on occasion .
--
http://mail.python.org/mailman/listinfo/python-list
John Bausano <[EMAIL PROTECTED]> wrote:
> Hello all,
>
>
>
> I've been using Ansys which is a commercial FEA package which can be
> controlled through its own scripting language they call APDL. Now I'm
> trying to write some stand alone code in Python to supplement my current
> efforts.
>
>
It'd be silly to write the code for it if it already
exists somewhere in the Python re or sre library
module:
I need to find and replace all strings in a text file
from a certain pattern to another pattern.
so for example if I see 'this(\D*)that' anywhere in
the file then I'd like to make is 'tha
re.replace.
I don't think there's any way to avoid it. Except maybe having an alias
email address or a fake one.
--
http://mail.python.org/mailman/listinfo/python-list
"Deval L" wrote:
> re.replace.
There isn't a re.replace; be careful when you reply to newbies.
> "Vibha Tripathi" wrote:
>
> > It'd be silly to write the code for it if it already
> > exists somewhere in the Python re or sre library
> > module:
> >
> > I need to find and replace all strings in a
Hrm, thought it had one. Guess it would help if I actually used regular
expression for replacement.
--
http://mail.python.org/mailman/listinfo/python-list
You might want to be a little more explicit. Do you know that
this = "this"
that = "that"
or do you mean
this = `the part before the \D*`
that = `the part after the \D*`
If you mean the former, then the previously proposed
py> import re
py> line = 'see this man with that woman holding this do
7;1','\\n',s)
'\n'
>>> '\\n'
'\\n'
>>> re.sub('1',r'\\n',s)
'\\n'
>>> s.replace('1','\\n')
'\\n'
>>> repl = '\\n'
>>> re.sub('1',repl,s)
'\n'
>>> s.replace('1',repl)
'\\n'
Why is the behaviour of the regexp substitution so weird and can I prevent
that? It breaks my asumptions and thus my code.
Regards,
Florian Schulze
--
http://mail.python.org/mailman/listinfo/python-list
=1,B=2))
True
>>> eval(z.func_code,dict(A=1,B=2, f1=f1))
Traceback (most recent call last):
File "", line 1, in ?
File "", line 1, in z
File "", line 1, in f1
NameError: global name 'A' is not defined
>>>
ENDTEST
===
Is there a wa
import re
>>>> s = "1"
>>>> re.sub('1','\\n',s)
>
> '\n'
>
>>>> '\\n'
>
> '\\n'
>
>>>> re.sub('1',r'\\n',s)
>
> '\\n'
>
>>>>
My initial feeling is that concatenation might take longer than
substitution, but that it is also easier to read:
def p(self, paragraph):
self.source += '' + paragraph + '\n\n'
vs.
def p(self, paragraph):
self.source += '%s\n\n' % paragraph
Is there
in ?
File "", line 1, in z
File "", line 1, in f1
NameError: global name 'A' is not defined
ENDTEST
===
Is there a way to do a deep substitution of the globals?
I should add that f1 is given as-is. I can modify z,
and f1 is just one of many functions given and function z
is some boolean function of the f's
Thanks, Pad.
--
http://mail.python.org/mailman/listinfo/python-list
dict(A=1,B=2, f1=f1))
Traceback (most recent call last):
File "", line 1, in ?
File "", line 1, in z
File "", line 1, in f1
NameError: global name 'A' is not defined
ENDTEST
===
Is there a way to do a deep substitution of the globals?
A workaro
Thanks Kent for your reply.
I had to do as you suggest but I was thinking either it was a kludge,
and there should be a 'deep' substitution of globals, or that there was
a good reason for it to work as it does and some magician would tell
me.
Oh, the third reason could be that it
Paddy wrote:
I had to do as you suggest but I was thinking either it was a kludge,
and there should be a 'deep' substitution of globals, or that there
was a good reason for it to work as it does and some magician would
tell me.
If there was deep substitution of globals, how would
Leif wrote:
" If globals were deeply substituted when using eval, the program would
presumably print "42\n24", which would be far from intuitive. If you
limit the deep substitution to functions in the same module, you're
creating a confusing special case. "
I guess I
Paddy wrote:
I do in fact have the case you mention. I am writing a module that will
manipulate functions of global variables where the functions are
defined in another module.
Would it be possible to have your functions take arguments instead of globals? That would seem to be
a better design.
Ke
John Salerno wrote:
> My initial feeling is that concatenation might take longer than
> substitution
Doesn't look that way:
[EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'"
100 loops, best of 3: 0.6 usec per loop
[EMAIL PROTECTED]:~
niether .join() is the fastest
--
http://mail.python.org/mailman/listinfo/python-list
fuzzylollipop wrote:
> niether .join() is the fastest
Please quote what you're replying to.
No, it's the slowest:
[EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'"
100 loops, best of 3: 0.607 usec per loop
[EMAIL PROTECTED]:~$ python -m timeit "'' + 'foobar' + '\n\n'"
100 loops
Leif K-Brooks wrote:
> fuzzylollipop wrote:
>> niether .join() is the fastest
>
> Please quote what you're replying to.
>
> No, it's the slowest:
>
> [EMAIL PROTECTED]:~$ python -m timeit "'%s\n\n' % 'foobar'"
> 100 loops, best of 3: 0.607 usec per loop
> [EMAIL PROTECTED]:~$ python -m time
In article <[EMAIL PROTECTED]>,
John Salerno <[EMAIL PROTECTED]> wrote:
> My initial feeling is that concatenation might take longer than
> substitution, but that it is also easier to read:
>
>
> def p(self, paragraph):
> self.source += '' + par
Roy Smith wrote:
> One may be marginally faster, but they both require copying the source
> string, and are thus both O(n).
Sorry, I'm not familiar with the O(n) notation.
> If you're just doing one or a small fixed
> number of these, it really doesn't matter. Pick whichever one you think is
Duncan Booth wrote:
> If you build a
> list of lines to join then you don't have to repeat '\n' on the end of each
> component line.
How would that work? Wouldn't the last line in the list still need the
newlines?
--
http://mail.python.org/mailman/listinfo/python-list
John Salerno wrote:
> Duncan Booth wrote:
>
>> If you build a
>> list of lines to join then you don't have to repeat '\n' on the end of
>> each component line.
>
> How would that work? Wouldn't the last line in the list still need the
> newlines?
>>> chunks = ["alpha", "beta", "gamma"]
>>> "\n"
John Salerno <[EMAIL PROTECTED]> wrote:
>Roy Smith wrote:
>
>> One may be marginally faster, but they both require copying the source
>> string, and are thus both O(n).
>
>Sorry, I'm not familiar with the O(n) notation.
OK, here's a quick tutorial to "big-oh" notation. It's a way of
measuring a
Thank you Roy.
It seems if you lurk here long enough you eventually get all you
questions answered without even asking!
;-)
Roy Smith wrote:
> John Salerno <[EMAIL PROTECTED]> wrote:
> >Roy Smith wrote:
> >
> >> One may be marginally faster, but they both require copying the source
> >> string,
Roy Smith wrote:
> OK, here's a quick tutorial to "big-oh" notation.
Wow, that was fantastic (and interesting)! Did you just write that? That
should be saved somewhere! Mind if I post it on my website? (don't
worry, no one goes there anyway) :)
--
http://mail.python.org/mailman/listinfo/pytho
In article <[EMAIL PROTECTED]>,
John Salerno <[EMAIL PROTECTED]> wrote:
>Roy Smith wrote:
>
>> OK, here's a quick tutorial to "big-oh" notation.
>
>Wow, that was fantastic (and interesting)! Did you just write that? That
>should be saved somewhere! Mind if I post it on my website? (don't
>worry
Roy Smith wrote:
> In article <[EMAIL PROTECTED]>,
> John Salerno <[EMAIL PROTECTED]> wrote:
>> Roy Smith wrote:
>>
>>> OK, here's a quick tutorial to "big-oh" notation.
>> Wow, that was fantastic (and interesting)! Did you just write that? That
>> should be saved somewhere! Mind if I post it on
[EMAIL PROTECTED] (Roy Smith) wrote:
>O(n^0), which is almost always written as O(1). This is a "constant
>time" algorithm, one which takes the same amount of steps to execute
>no matter how big the input is. For example, in python, you can
>write, "x = 'foo'". That assignment statement takes t
In article <[EMAIL PROTECTED]>,
Casey Hawthorne <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] (Roy Smith) wrote:
>
> >O(n^0), which is almost always written as O(1). This is a "constant
> >time" algorithm, one which takes the same amount of steps to execute
> >no matter how big the input is.
Ted wrote:
> Thank you Roy.
>
> It seems if you lurk here long enough you eventually get all you
> questions answered without even asking!
> ;-)
>
+1 QOTW
please avoid top-posting, and please avoid posting back a long message
just to add three lines.
--
bruno desthuilliers
python -c "print '
41 matches
Mail list logo