by using __repr__(), is there a way to omit the trailing L when representing a (num/den)?
6 2301 bvdet 2,851
Expert Mod 2GB
by using __repr__(), is there a way to omit the trailing L when representing a (num/den)?
- >>> repr(5788769978008/2)
-
'2894384989004L'
-
>>> repr(str(5788769978008/2))
-
"'2894384989004'"
-
>>> repr(float(5788769978008/2))
-
'2894384989004.0'
-
>>> repr(float(5788769978008/2))[:-2]
-
'2894384989004'
-
>>>
HTH,
BV
by using __repr__(), is there a way to omit the trailing L when representing a (num/den)?
How about just
>>> str(5788769978008/2)
'2894384989004'
>>>
ok, make it a string. I see. Thank you
ok, make it a string. I see. Thank you
You are welcome.
Another way is to use python's c-like sting formatting to do the job: - print "This is a long: %i" % 12345123451234512345L
-
-
print "Here are a few values: a string %s; a float %7.3f; an integer %-5i" % ("doobery",1234.567,0123)
It's generally more efficient (and readable and maintainable) to use string formats for complex output, but if you just want to print a number, it can be cumbersome. Your call.
hth,
-cybervegan
Another way is to use python's c-like sting formatting to do the job: - print "This is a long: %i" % 12345123451234512345L
-
-
print "Here are a few values: a string %s; a float %7.3f; an integer %-5i" % ("doobery",1234.567,0123)
It's generally more efficient (and readable and maintainable) to use string formats for complex output, but if you just want to print a number, it can be cumbersome. Your call.
hth,
-cybervegan
Great post, cybervegan. Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alberto Vera |
last post by:
Hello:
I have the next structure:
How Can I make it using Python?
How Can I update the value of 6?
|
by: Java and Swing |
last post by:
Hi,
I have been posting about writing a C extension for Python...so far,
so good. At least for the "simple" functions that I need to wrap.
Ok, my c function looks like...
MY_NUM...
|
by: Stan Shankman |
last post by:
How do I add trailing spaces within a right-justified textBox?
In order to add a trailing space to the text in a right-justified textBox,
I use to just append a space to the end of the text...
|
by: Seth |
last post by:
First off, my apologies if this is in the wrong newsgroup, but I hope
I'm close enough.
I'm trying to do some parsing of a CSV file using OleDbConnection, but
for some reason, when I populate my...
|
by: Albert |
last post by:
This isn't entirely related to C, but Kernighan and Ritchie asks in
Execise 1-18 of their C programming language book to 'Write a program
to remove trailing blanks and tabs from each line of input,...
|
by: tommy |
last post by:
Hi all,
I' m adding strings to some fields in my table via Access. The strings
sometimes have trailing spaces and I really need to have it that way,
but Access truncates trailing spaces. How can...
|
by: David |
last post by:
Below are three classes for a console application. If put into three
separate files, the sub main() will launch multiple threads adding and
removing the same value. At the end we expect the value...
|
by: Chester |
last post by:
I'm working on an app that records data collected by service
technicians (VB.Net front-end, SQL Server 2000 back end). The
technicians need to record numbers with varying scale and precision.
For...
|
by: brian.j.parker |
last post by:
Hey all, I've noticed an obscure little quirk: it appears that if you
use a login with trailing spaces on the name, SYSTEM_USER
automatically trims those trailing spaces in SQL Server 2000, but not...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |