I am using Python 2.5.2
>>> for x in range(1,11):
print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)
Traceback (most recent call last):
File "", line 2, in
print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)
AttributeError: 'str' object has no attribute 'format'
I am not getting the problem
When i did dir('hello') there was no...
import sys
try:
raise "xxx"
except str,e:
print "1",e
except:
print "2",sys.exc_type,sys.exc_value
In the above code a string exception is raised which though deprecated but still a 3rd party library I use uses it.
So how can I catch such exception without relying on catch all, which could be bad.
except str,e: doesn't cat...
Why do you need to use the function 'str' in the following code?
I am trying to count the sum of digits in a number.
My code
for i in number:
sum(map(int, str(i))
where number is the following array
[7,79,9]
I read my code as follows
loop though the array such that
count sum of the integer digits
by getting given digits in ...
What is the reason that you cannot use zero at the beginning of a number when converting the number to a sequence?
Code example
map(int,str(08978789787))
which gives Syntax error.
I would like to convert numbers which leading digit is zero to a sequence.
How can you convert such a number to a sequence?
...
>>> float(str(0.65000000000000002))
0.65000000000000002
>>> float(str(0.47000000000000003))
0.46999999999999997 ???
What is going on here and how do I convert 0.47000000000000003 to string and the resultant value back to float?
I am using python 2.5.4 on windows.
...
I'm trying to print cards using their suit unicode character and their values. I tried doing to following:
def __str__(self):
return u'\u2660'.encode('utf-8')
like suggested in another thread, but I keep getting errors saying UnicodeEncodeError: ascii, ♠, 0, 1, ordinal not in range(128). What can I do to get those suit character t...
Hello,
I'm trying to convert a standard SQL query to a LINQ to SQL query.
I was wondering what the LINQ equivalent of the T-SQL function STR() is?
STR (T-SQL)
Returns character data converted from
numeric data.
Syntax STR(float_expression[, length[,
decimal]])
Arguments float_expression Is an
expression of app...
I receive
TypeError: Can't convert 'float' object to str implicitly
while using
Gambler.pot += round(self.bet + self.money * 0.1)
where pot, bet, and money are all doubles (or at least are supposed to be). I'm not sure if this is yet another Eclipse thing, but how do I get the line to compile?
Code where bet and money are initiali...
I've got a Python program that stores and writes data to a file. The data is raw binary data, stored internally as str. I'm writing it out through a utf-8 codec. However, I get UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 25: character maps to <undefined> in the cp1252.py file.
This looks to me like Python i...
Why I have problem creating a class the inherite from str (or also int)
class C(str):
def __init__(self, a, b):
str.__init__(self,a)
self.b = b
C("a", "B")
TypeError: str() takes at most 1 argument (2 given)
tha same happens if I try to use int instead of str, but it works with custom classes. I need to use __new__ inst...
for example the following:
str(u'לשום')
will throw an error.
how can i prevent these?
...
I asked a question regarding how to display aspx and cs code on page,
One answer was to convert to string and display in textbox.
Is there a function in C# ASP.NET which allows to convert file contents directly to a string?
...
Hi All,
Please excuse my noob-iness!
I have a $string, and would like to see if it contains any one or more of a group of words, words link c*t, fu*, sl** ETC. So I was thinking I could do:
if(stristr("$input", "dirtyword1"))
{
$input = str_ireplace("$input", "thisWillReplaceDirtyWord");
}
elseif(stristr("$input", "dirtyWord1"))
{
...
Well this interactive python console snippet will tell everything:
>>> class Test:
... def __str__(self):
... return 'asd'
...
>>> t = Test()
>>> print t
asd
>>> l = [Test(), Test(), Test()]
>>> print l
[__main__.Test instance at 0x00CBC1E8, __main__.Test instance at 0x00CBC260,
__main__.Test instance at 0x00CBC238]
...