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

Where can I find string.translate source?

The module string has a function called translate. I tried to find the
source code for that function. In:

C:\Python24\Lib

there is one file called

string.py

I open it and it says

"""A collection of string operations (most are no longer used).
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are implemented as
methods on the standard string object. They used to be implemented by
a built-in module called strop, but strop is now obsolete itself."""

Inside the file string.py I couldn't find the source code for
translate. Where could it be?

Nov 22 '05 #1
6 2720
bo*******@yahoo.com writes:
Inside the file string.py I couldn't find the source code for
translate. Where could it be?


Object/stringmodule.c in the python source distribution.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 22 '05 #2
bo*******@yahoo.com writes:
Inside the file string.py I couldn't find the source code for
translate. Where could it be?


Object/stringmodule.c in the python source distribution.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 22 '05 #3
bo*******@yahoo.com wrote:
The module string has a function called translate. I tried to find the
source code for that function. In:

C:\Python24\Lib

there is one file called

string.py

I open it and it says

"""A collection of string operations (most are no longer used).
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are implemented as
methods on the standard string object. They used to be implemented by
a built-in module called strop, but strop is now obsolete itself."""

Inside the file string.py I couldn't find the source code for
translate. Where could it be?


in the string.py module, of course.

if you read that comment again, you'll notice that it says

many of these functions are implemented as methods on the
standard string object

and if you search for translate in string.py, you'll also find the source
code for the translate function

# Character translation through look-up table.
def translate(s, table, deletions=""):
/... docstring snipped .../
if deletions:
return s.translate(table, deletions)
else:
# Add s[:0] so that if s is Unicode and table is an 8-bit string,
# table is converted to Unicode. This means that table *cannot*
# be a dictionary -- for that feature, use u.translate() directly.
return s.translate(table + s[:0])

which calls the translate method to do the work, just as the comment
said.

to find the method implementation, you have to look at the string object
implementation. it's in the Objects directory in the source distribution.

</F>

Nov 22 '05 #4
bo*******@yahoo.com wrote:
The module string has a function called translate. I tried to find the
source code for that function. In:

C:\Python24\Lib

there is one file called

string.py

I open it and it says

"""A collection of string operations (most are no longer used).
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are implemented as
methods on the standard string object. They used to be implemented by
a built-in module called strop, but strop is now obsolete itself."""

Inside the file string.py I couldn't find the source code for
translate. Where could it be?


in the string.py module, of course.

if you read that comment again, you'll notice that it says

many of these functions are implemented as methods on the
standard string object

and if you search for translate in string.py, you'll also find the source
code for the translate function

# Character translation through look-up table.
def translate(s, table, deletions=""):
/... docstring snipped .../
if deletions:
return s.translate(table, deletions)
else:
# Add s[:0] so that if s is Unicode and table is an 8-bit string,
# table is converted to Unicode. This means that table *cannot*
# be a dictionary -- for that feature, use u.translate() directly.
return s.translate(table + s[:0])

which calls the translate method to do the work, just as the comment
said.

to find the method implementation, you have to look at the string object
implementation. it's in the Objects directory in the source distribution.

</F>

Nov 22 '05 #5
Thanks Mike and Fredrik. In my Python installation there is no
directory called Objects.

I use Windows and I downloaded Python from
http://www.python.org/download/

As I looked closer I saw that the link
# Python 2.4.2 Windows installer (Windows binary -- does not
include source)

which clearly says that it doesn't include source. So in order to see
the source I had to download
# Python 2.4.2 source (for Unix or OS X compile)

And in that download there is a directory called Objects and there is
file called
stringobjects.c
where one can find the implementation of translate.

Nov 22 '05 #6
Thanks Mike and Fredrik. In my Python installation there is no
directory called Objects.

I use Windows and I downloaded Python from
http://www.python.org/download/

As I looked closer I saw that the link
# Python 2.4.2 Windows installer (Windows binary -- does not
include source)

which clearly says that it doesn't include source. So in order to see
the source I had to download
# Python 2.4.2 source (for Unix or OS X compile)

And in that download there is a directory called Objects and there is
file called
stringobjects.c
where one can find the implementation of translate.

Nov 22 '05 #7

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

Similar topics

5
by: Donnie Leen | last post by:
I make program in c++ embedding python2.4 in windows, I need the python24_d.lib to link with the debug version of my program, but i can't find the source code to build python24_d.lib on the...
0
by: Robin Tucker | last post by:
I'm localizing and need to find all string literals in my source code. I don't want to find any of the literals that will end up in resources however. As I don't use the "Me" keyword, I know...
0
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
2
by: Bryan_Cockrell | last post by:
Hi World, I am extracting text from an ebcdic header using dd in the cygwin environment (bash/ksh) as below in order to rename the file to something intelligent. I'm using a specific string...
1
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
4
by: xdevel | last post by:
Hi, if I want to read the string functions source code (i.e. strcpy, strtok etc.) where can I find them?
1
by: BlueJumper.com | last post by:
Does anyone know where I can find a decent standards compliant menu control to replace the .Net 2.0 Menu controls (and tree control for that matter!) At present the control renders as a table...
4
by: destroooooy | last post by:
Hi folks, I'm finding some (what I consider) curious behavior with the string methods and the forward slash character. I'm writing a program to rename mp3 files based on their id3 tags, and I want...
0
by: tvnaidu | last post by:
gdb list command - doesnot show source - where I should copy source ? # gdb /pfrm2.0/bin/cacd Could not find platform independent libraries <prefix> Could not find platform dependent libraries...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.