473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trailing L on Longs

TMS
119 100+
by using __repr__(), is there a way to omit the trailing L when representing a (num/den)?
Feb 8 '07 #1
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)?
Expand|Select|Wrap|Line Numbers
  1. >>> repr(5788769978008/2)
  2. '2894384989004L'
  3. >>> repr(str(5788769978008/2))
  4. "'2894384989004'"
  5. >>> repr(float(5788769978008/2))
  6. '2894384989004.0'
  7. >>> repr(float(5788769978008/2))[:-2]
  8. '2894384989004'
  9. >>> 
HTH,
BV
Feb 8 '07 #2
bartonc
6,596 Expert 4TB
by using __repr__(), is there a way to omit the trailing L when representing a (num/den)?
How about just

>>> str(5788769978008/2)
'2894384989004'
>>>
Feb 9 '07 #3
TMS
119 100+
ok, make it a string. I see. Thank you
Feb 10 '07 #4
bartonc
6,596 Expert 4TB
ok, make it a string. I see. Thank you
You are welcome.
Feb 10 '07 #5
Another way is to use python's c-like sting formatting to do the job:

Expand|Select|Wrap|Line Numbers
  1. print "This is a long: %i" % 12345123451234512345L
  2.  
  3. 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
Feb 15 '07 #6
bartonc
6,596 Expert 4TB
Another way is to use python's c-like sting formatting to do the job:

Expand|Select|Wrap|Line Numbers
  1. print "This is a long: %i" % 12345123451234512345L
  2.  
  3. 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.
Feb 15 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

27
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?
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...
5
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...
0
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...
4
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,...
17
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...
12
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...
9
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...
5
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...
0
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,...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.