473,386 Members | 1,654 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,386 software developers and data experts.

Python for Visual Basic or C# programmers

A.M
Hi,

I am trying to find the equivalent functions such as vb's str or asc in
Python. Is there any resource that help me to find these kinds of functions
in Python faster?

Thank you,

Alan
Jun 1 '06 #1
6 1747
A.M wrote:
Hi,

I am trying to find the equivalent functions such as vb's str or asc in
Python. Is there any resource that help me to find these kinds of functions
in Python faster?

Thank you,

Alan
Alan


Python has a str() function that is close to vb's str. The Python
version does not produce a leading space.
str(123) --> '123'

If you want to control the formatting to mimick vb or create different
formatting you can use.
" %d" % 123 --> ' 123'
The format specifier is just like 'C's printf format strings.
A tuple should follow the % sign if formatting more than 1 number.
"%d %d" % (123, 456)

Python has a similar function to vb's asc.
It is ord().
ord() accepts a single character, whereas asc operates on the first
character of a string.
To mimick vb you could do
s = 'hello'
ord(s[0]) --> 104

I am unaware of any reference associating vb functionality with Python
functionality.
Then again, I never looked for one.

Jun 1 '06 #2
A.M wrote:
I am trying to find the equivalent functions such as vb's str or asc in
Python. Is there any resource that help me to find these kinds of functions
in Python faster?


The Library Reference has a section on built-in functions:
http://docs.python.org/lib/built-in-funcs.html

Also take a look at the section on string methods:
http://docs.python.org/lib/string-methods.html

Kent
Jun 1 '06 #3
Slight correction.
" %d" % 123 is not quite equivalent to str(123) as it does not handle
negative numbers the same way.
I am not sure there is a simple direct equivalent.
"%+d" % 123 --> "+123" always gives a sign.
"%4d" % 123 --> " 123"
"%4d" % -123 --> "-123" so this works if you you know how wide the
number is.

This might be a little too tricky.
[" %d", "%d][n < 0] % n --> selects list[0] or list[1] based upon sign
of number

Jun 1 '06 #4
Max
Metalone wrote:
<on imitatting VB's irritating space-or-minus>

This might be a little too tricky.
[" %d", "%d][n < 0] % n --> selects list[0] or list[1] based upon sign
of number


("%+d" % 123).replace("+", " ") is slightly longer but instantly
comprehensible, although I for one think your boolean indexing trick is
cool.

--Max
Jun 1 '06 #5
A.M a écrit :
Hi,

I am trying to find the equivalent functions such as vb's str or asc in
Python. Is there any resource that help me to find these kinds of functions
in Python faster?


<mode pub="on">

I've written the PQRC for that purpose:
http://www.limsi.fr/Individu/pointal/python/pqrc/

</mode>

A+

Laurent.
Jun 2 '06 #6
On Fri, Jun 02, 2006 at 10:26:28AM +0200, Laurent Pointal wrote:
A.M a ?crit :
Hi,

I am trying to find the equivalent functions such as vb's str or asc in
Python. Is there any resource that help me to find these kinds of functions
in Python faster?
<mode pub="on">

I've written the PQRC for that purpose:
http://www.limsi.fr/Individu/pointal/python/pqrc/

</mode>

There is also the Python Quick reference series:
http://rgruet.free.fr/#QuickRef
A+

Laurent.
--
http://mail.python.org/mailman/listinfo/python-list

Jun 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
46
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
38
by: kbass | last post by:
In different articles that I have read, persons have constantly eluded to the productivity gains of Python. One person stated that Python's productivity gain was 5 to 10 times over Java in some in...
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
17
by: MilkmanDan | last post by:
I'll be a college freshman this fall, attending Florida Institute of Tech studying electrical engineering. I was considering taking some classes in programming and computer science, and I...
31
by: stéphane bard | last post by:
hello, my boss ask me to prefer windev to python. I have to argue - python work on multiple platform (linux, mac, windows) A good point but it didn't interest him. Because we want to choose a...
0
by: Gabriel Genellina | last post by:
QOTW: "I think the need for these 'eventloop unifications' stems from Visual Basic. VB programmers never learned to use more than one thread, and they are still struggling to unlearn the bad...
62
by: estherschindler | last post by:
This is part of a series examining the strengths and weaknesses of various scripting languages, with particular attention to enterprise (read: big company) use. You Used Python to Write WHAT?...
61
by: giveitawhril2008 | last post by:
I'm just learning about Python now and it sounds interesting. But I just read (on the Wiki page) that mainstream Python was written in C. That's what I was searching for: Python was written in what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.