473,396 Members | 1,966 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,396 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 2719
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.