somestring = ABC
somestring2 = somestring + D
somestring2 += EF
assert somestring2 == ABCDEF
assert somestring == ABC
assert id(somestring) != id(somestring2)
Basically, strings are immutable. If you need to append something to a
string, you need to construct a new string object with the new
Beside casting it with str(), you can also use a format string:
assert %d % 10 == 10
assert %5d % 10 ==10
assert %05d % 10 == 00010
In practice % supports a superset of what printf in C provides.
Andreas
Am Freitag, den 21.03.2008, 17:05 -0700 schrieb elis aeris:
how do I convert int to
Well, there are basically two ways to go at it.
If you want it at module level, you need to generate the functions:
sensor = {'sens1': 200, 'sens2': 300}
for key in sensor.keys():
def helper(keytofetch=key):
return sensor[keytofetch]
globals()[key] = helper
print sens1()
Well, it's classmethod/staticmethod in truth, @ is the decorator
operator:
def testdec(func):
return {funcobj: func}
class Abc(object):
@testdec
def method():
pass
assert isinstance(Abc.method, dict)
Basically as you can see above, @X before a function definition takes
the
import re
num = 123456789
print ','.join(re.findall(\d{3}, str(num)))
output:
123,456,789
- Original Message -
From: [EMAIL PROTECTED]
To: tutor@python.org
Date: Fri, 21 Mar 2008 21:49:18 -0700
Subject: [Tutor] Even More Converter!
It works perfectly, so I am sure my question will
Hello,
Please excuse me in advance if this post is long winded. I have the
following nagging issue for which I have found a work around, but wanted
a better solution.
I am using jQuery to populate tabs with some data, such as news and jobs
posts, as can be seen at http://uk.expert.travel
In
Shrutarshi Basu wrote:
There are two solutions I've thought about:
Have a function that takes in the sensor's name as a string and
responds accordingly. (which might be what I'll end up using)
That is almost the same as using ordinary dict access, with slightly
different syntax, e.g.
import re
num = 12345678
print ','.join(re.findall(\d{3}, str(num)))
output:
123,456
Where is the '78'?
It looks like that solution inserts comma's from left to right
instead of from right to left.
--
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying
Kepala Pening wrote:
import re
num = 123456789
print ','.join(re.findall(\d{3}, str(num)))
output:
123,456,789
[snip]
The problem with that is that it cuts the digits in the end of the
number, if they can't form a 3 digit value.
Example:
import re
n = 1234
print
[EMAIL PROTECTED] wrote:
When Python gives me the answer to my conversion, is there a way to create it
so every 3 numbers a comma is inserted?
Django uses this function:
def intcomma(value):
Converts an integer to a string containing commas every three digits.
For example, 3000
maser [EMAIL PROTECTED] wrote
I couldn't find a good resource explaining what
@classmethod and @staticmethod are in python and when,
how these could be used.
I'm not sure which aspect of this is the problem
Andreas has explained the strange @ syntax for a decorator
however if its the
How about:
def intCommas(n):
inserts commas into integers. E.g. -12345678 -
-12,345,789
s = str(n)
sign = ''
if s[0] == '-':
sign = '-'
s = s[1:]
slen = len(s)
a = ''
for index in range(slen):
if index 0 and index % 3
== slen % 3:
a = a
+ ','
a = a + s[index]
return sign + a
sorry, I forgot that re search from the front of the string.
import re
putComma = lambda x: (','.join(re.findall(\d{1,3}, str(x)[::-1])))[::-1]
print putComma(1234567) # 1,234,567
print putComma(12345678)# 12,345,678
print putComma(123456789) # 123,456,789
- Original Message
Alan Gauld wrote:
If that is important you might need to investigate a locale specific
way of defining the seperator. I know Windows has hooks to get
it from the local settings but I'm not sure about *nix and I don't
know if Python has a generic way.
This might not matter to you in
Alan Gauld wrote:
Bear in mind that the use of commas is very much a
local thing. In some parts of the world periods are used
and a comma indicates a decimal point so
123,456
could be 123 thousand 456 or 123 point 456 depending
on where the reader is from.
If that is important you
how do I pop up a window to ask user's input?
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
chat_window_char_definition = { 2.7.1. : 1,
2.3.3.3.3. : 2,
2.2.3.3.4. : 3,
2.2.2.7.1. : 4,
4.3.3.3.4. : 5,
}
how
elis aeris wrote:
chat_window_char_definition = { 2.7.1. : 1,
2.3.3.3.3. : 2,
2.2.3.3.4. : 3,
2.2.2.7.1. : 4,
4.3.3.3.4. : 5,
how about console window input?
On Sat, Mar 22, 2008 at 3:02 PM, Kent Johnson [EMAIL PROTECTED] wrote:
elis aeris wrote:
how do I pop up a window to ask user's input?
Take a look at
http://www.ferg.org/easygui/
Kent
___
Tutor maillist -
there is no pattern in the numbers. but don't worry about it, because all i
am doing is this:
two strings that look like 2.3.3.3.3., youknow, str(int) + . +
str(int) + . and so forth
are presented and they equal to a value, which is the third string.
in short, given the first two strings,
elis aeris wrote:
how do I pop up a window to ask user's input?
Take a look at
http://www.ferg.org/easygui/
Kent
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Norman Khine wrote:
I would like to alter this batch control so that I don't have to create
a new method everytime I need a new tab.
For example, I would like to change t1, t2 ... t[n] depending on the tab
I am at.
I don't really understand the question but I think maybe the tabs should
oh sorry, I should have been clear:
how about just popping a prompt in the same window that is running the
script?
On Sat, Mar 22, 2008 at 3:09 PM, Kent Johnson [EMAIL PROTECTED] wrote:
elis aeris wrote:
how about console window input?
You want to pop up a console window? Usually if your
elis aeris wrote:
how about console window input?
You want to pop up a console window? Usually if your program is
running in a console you have a window already. Use raw_input() to get
user input in the console.
Kent
On Sat, Mar 22, 2008 at 3:02 PM, Kent Johnson [EMAIL PROTECTED]
elis aeris wrote:
there is no pattern in the numbers.
Then how do you expect to create them automatically? I don't understand
that part of the question.
two strings that look like 2.3.3.3.3., youknow, str(int) + . +
str(int) + . and so forth
are presented and they equal to a value,
on a different note, also on lists, I need to save two values, x and y.
list = { int, int
int, int
int, int
but i am not sure of the syntax, is it possible to just read both values
from the same entry in the list ?
___
Tutor
Another part of program takes care of that patternless stuff, only saving
and retrieving for comparison is concerned for this part of the code.
In [11]: d = { ('a', 'b'): '1',
: ('c', 'd'): '2' }
In [12]:
In [12]: d['a', 'b']
Out[12]: '1'
that does look like what I looking for, how does
elis aeris wrote:
oh sorry, I should have been clear:
how about just popping a prompt in the same window that is running the
script?
Sounds like you want raw_input():
http://docs.python.org/lib/built-in-funcs.html#l2h-59
Kent
___
Tutor maillist
sweet, I love built in functions. thanks !
On Sat, Mar 22, 2008 at 3:15 PM, Kent Johnson [EMAIL PROTECTED] wrote:
elis aeris wrote:
oh sorry, I should have been clear:
how about just popping a prompt in the same window that is running the
script?
Sounds like you want raw_input():
elis aeris [EMAIL PROTECTED] wrote
on a different note, also on lists, I need to save two values, x
and y.
list = { int, int
int, int
int, int
but i am not sure of the syntax, is it possible to just read both
values
from the same entry in the list ?
I have no
I just need a way to key a list of tuples of 2 for referencing.
On Sat, Mar 22, 2008 at 3:48 PM, Alan Gauld [EMAIL PROTECTED]
wrote:
elis aeris [EMAIL PROTECTED] wrote
on a different note, also on lists, I need to save two values, x
and y.
list = { int, int
int, int
elis aeris [EMAIL PROTECTED] wrote
I just need a way to key a list of tuples of 2 for referencing.
I have no idea what you mean by that, can you give a more
specific example?
OK, I have now read your discussion with Kent.
Can i ask, have you tried going through any of the basic tutorials?
On Sat, Mar 22, 2008 at 09:46:58AM +0100, Andreas Kostyrka wrote:
Basically, strings are immutable. If you need to append something to a
string, you need to construct a new string object with the new value.
Now if you are using this to collect huge outputfiles in pieces, one of
the common
Hello,
As someone relatively new to programming, I've a few questions related
to the Global Module Index:
http://docs.python.org/modindex.html
What are the distinctions between a library and a module? Do people
frequently use the terms interchangeably in conversations, mailng
lists, and
r dascenzo wrote:
What are the distinctions between a library and a module? Do people
frequently use the terms interchangeably in conversations, mailng
lists, and around the web?
module is very specific, it is a single Python source file. A library
is a collection of useful modules.
[EMAIL PROTECTED] wrote:
I am still in need of more help. Currently I am just trying to get one
conversion down, as then I can duplicate it. However I am not sure how to
make it Convert. Currently I am working with:
# Converter
Original = raw_input(Insert inches, feet )
There is a
I've used pexpect for a few projects and love it. Basically pexpect
lets you spawn a program and interact with it from code like you
yourself were running it in a console. How would you send the ctrl key?
nomb
___
Tutor maillist - Tutor@python.org
37 matches
Mail list logo