473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Anything like 'inspect.getsourceencoding()'?

Is there a convenient way to find the encoding of a source file? I
thought maybe this would be in the inspect module, but I didn't see it
there. Just as nice would be a way to get the file as a unicode string,
I suppose.

(This is related to another thread I've recently posted to, where
another user was having trouble with pydoc's links to source files using
the file: protocol. I suggested having pydoc serve the source files,
and provided a patch, but it's crossed my mind that it would be nice to
tell the browser the encoding of that file.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBcdWJJd01MZaTXX0RAnyUAJ9dN2Shq85BpM/LH6+QinvL3OD40gCfW7Hb
1zvj6WpqwJbtTk1bA1+4+nM=
=K3uY
-----END PGP SIGNATURE-----

Jul 18 '05 #1
2 1056
Jeff Epler wrote:
Is there a convenient way to find the encoding of a source file? I
thought maybe this would be in the inspect module, but I didn't see it
there. Just as nice would be a way to get the file as a unicode string,
I suppose.

(This is related to another thread I've recently posted to, where
another user was having trouble with pydoc's links to source files using
the file: protocol. I suggested having pydoc serve the source files,
and provided a patch, but it's crossed my mind that it would be nice to
tell the browser the encoding of that file.

Jeff


According to Python documentation:

It is possible to use encodings different than ASCII in Python source files.
The best way to do it is to put one more special comment line right after
the #! line to define the source file encoding:

# -*- coding: iso-8859-1 -*-
--
Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl)
www.fiedzia.prv.pl

How can you be ALONE with somebody? Think about it...
Jul 18 '05 #2
Jeff Epler wrote:
Is there a convenient way to find the encoding of a source file? I
thought maybe this would be in the inspect module, but I didn't see it
there. Just as nice would be a way to get the file as a unicode string,
I suppose.


No. inspect operates on the byte-code/internal representation level, and
at that level, there is no notion of source encoding. The source
encoding information gets lost during compilation (as it is no longer
needed).

Somebody proposed preserving it in __[en]coding__, but that hasn't been
implemented.

Regards,
Martin
Jul 18 '05 #3

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

Similar topics

4
by: Hans Georg Krauthaeuser | last post by:
Dear all, I have a problem to get the command that has called a function if the command was given on multiple lines. E.g.: ################################################### import inspect ...
1
by: Thomas Guettler | last post by:
Hi, the line numbers of inspect.getinnerframes are different from traceback.format_exception. This results in wrong lines being shown in cgitb. An example is below. I looked at the...
2
by: Fernando Perez | last post by:
Hi all, IPython has suffered quite a few problems with the inspect module in python 2.3. For these, unfortunately all I've been able to do is guard with overreaching except clauses, as I had...
11
by: It's me | last post by:
I discovered the hardway what inspect.isclass() is doing. Consider this no brainer code: ### import inspect class Abc: def Hello(self): return
1
by: Darran Edmundson | last post by:
I was playing around with the inspect module the other day trying to write a quick and dirty "smart" logger. By this I mean that writing a message to the global log would also yield some info...
0
by: Ron Adam | last post by:
While playing around with the inspect module I found that the Blockfinder doesn't recognize single line function definitions. Adding the following two lines to it fixes it, but I'm not sure if it...
1
by: aj | last post by:
What is the difference (if any) between inspect check database and db2dart ??? Do they both find the same potential problems? Does one provide more comprehensive checking than the other? ...
8
by: Aaron \Castironpi\ Brady | last post by:
Hello, The 'inspect' module has this method: inspect.getargvalues(frame) It takes a frame and returns the parameters used to call it, including the locals as defined in the frame, as shown....
0
by: rajasankar | last post by:
Hi, I am using Jython based application and trying to use inspect.py in the python files. Here is my code import inspect,os,sys,pprint,imp def handle_stackframe_without_leak(getframe): ...
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
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...
1
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
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.