473,785 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sys.stdin.encod ing

The following line in my code is failing because sys.stdin.encod ing is
Null. This has only started happening since I started working with
Pydef in Eclipse SDK. Any ideas?

uni=unicode(wor d,sys.stdin.enc oding)

Thanks,

Aine.

Dec 11 '06 #1
8 5074
ai********@yaho o.com wrote:
The following line in my code is failing because sys.stdin.encod ing is
Null.
I'll guess you mean None rather than Null.
This has only started happening since I started working with
Pydef in Eclipse SDK. Any ideas?

uni=unicode(wor d,sys.stdin.enc oding)
You could give it a fallback value:

uni = unicode(word, sys.stdin.encod ing or sys.getdefaulte ncoding())

or even just:

uni = unicode(word, sys.stdin.encod ing or 'ascii')

which should be the same in all reasonable universes (although I did get
bitten recently when someone had changed the default encoding in a system).
Dec 11 '06 #2
Duncan Booth skrev:
ai********@yaho o.com wrote:
The following line in my code is failing because sys.stdin.encod ing is
Null.

I'll guess you mean None rather than Null.
This has only started happening since I started working with
Pydef in Eclipse SDK. Any ideas?

uni=unicode(wor d,sys.stdin.enc oding)
You could give it a fallback value:

uni = unicode(word, sys.stdin.encod ing or sys.getdefaulte ncoding())

or even just:

uni = unicode(word, sys.stdin.encod ing or 'ascii')

which should be the same in all reasonable universes (although I did get
bitten recently when someone had changed the default encoding in a system).

Thanks for your help. The problem now is that I cant enter the Swedish
characters åöä etc without getting the following error -

Enter wordPåe
Traceback (most recent call last):
File "C:\Documen ts and Settings\worksp ace\simple\src\ main.py", line
25, in <module>
archive.Test()
File "C:\Documen ts and Settings\worksp ace\simple\src\ verb.py", line
192, in Test
uni=unicode(wor d,sys.stdin.enc oding or sys.getdefaulte ncoding())
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe5 in position 1:
ordinal not in range(128)

The call to sys.getdefaulte ncoding() returns ascii. Since I can enter
the characters åöä on the command line in Pydef/Eclipse doesn't that
mean that the stdin is not ascii? What should I do?

Thanks again,

Aine.

Dec 11 '06 #3
ai********@yaho o.com schrieb:
The following line in my code is failing because sys.stdin.encod ing is
Null. This has only started happening since I started working with
Pydef in Eclipse SDK. Any ideas?

uni=unicode(wor d,sys.stdin.enc oding)
That's a problem with pydev, where the standard machinery to determine
the terminal's encoding fail.

I have no idea yet how to fix this.

Regards,
Martin
Dec 11 '06 #4
ai********@yaho o.com wrote:
The call to sys.getdefaulte ncoding() returns ascii. Since I can enter
the characters åöä on the command line in Pydef/Eclipse doesn't that
mean that the stdin is not ascii? What should I do?
I think that depends on what sort of script you are writing.

If it is just something for personal use on a single machine, or if you
know that the same encoding is going to be used on all systems where you
have this problem, then you could hardwire the encoding to whatever it
should be (maybe 'latin1').

If it is to be used across a variety of systems with different encodings
then you'll have to figure out some way to find the correct encoding.
Dec 11 '06 #5

Duncan Booth skrev:
ai********@yaho o.com wrote:
The call to sys.getdefaulte ncoding() returns ascii. Since I can enter
the characters åöä on the command line in Pydef/Eclipse doesn't that
mean that the stdin is not ascii? What should I do?
I think that depends on what sort of script you are writing.

If it is just something for personal use on a single machine, or if you
know that the same encoding is going to be used on all systems where you
have this problem, then you could hardwire the encoding to whatever it
should be (maybe 'latin1').

If it is to be used across a variety of systems with different encodings
then you'll have to figure out some way to find the correct encoding.
Yeah I'm only learning python so I think I can go with latin1.

Cheers,

Aine.

Dec 11 '06 #6

ai********@yaho o.com wrote:
Duncan Booth skrev:
ai********@yaho o.com wrote:
The following line in my code is failing because sys.stdin.encod ing is
Null.
I'll guess you mean None rather than Null.
This has only started happening since I started working with
Pydef in Eclipse SDK. Any ideas?
>
uni=unicode(wor d,sys.stdin.enc oding)
>
You could give it a fallback value:

uni = unicode(word, sys.stdin.encod ing or sys.getdefaulte ncoding())

or even just:

uni = unicode(word, sys.stdin.encod ing or 'ascii')

which should be the same in all reasonable universes (although I did get
bitten recently when someone had changed the default encoding in a system).


Thanks for your help. The problem now is that I cant enter the Swedish
characters åöä etc without getting the following error -

Enter wordPåe
Traceback (most recent call last):
File "C:\Documen ts and Settings\worksp ace\simple\src\ main.py", line
25, in <module>
archive.Test()
File "C:\Documen ts and Settings\worksp ace\simple\src\ verb.py", line
192, in Test
uni=unicode(wor d,sys.stdin.enc oding or sys.getdefaulte ncoding())
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe5 in position 1:
ordinal not in range(128)

The call to sys.getdefaulte ncoding() returns ascii. Since I can enter
the characters åöä on the command line in Pydef/Eclipse doesn't that
mean that the stdin is not ascii? What should I do?
The workaround in your case is:

in the beginning of your program:

import sys
if hasattr(sys.std in, 'encoding'):
console_encodin g = sys.stdin.encod ing
else:
import locale
locale_name, console_encodin g = locale.getdefau ltlocale()

and later:

uni = unicode(word, console_encodin g)

But don't think it's portable, if you use other IDE or OS, it may not
work. It would be better if PyDev implemented sys.stdin.encod ing

-- Leo

Dec 11 '06 #7

Martin v. Löwis wrote:
ai********@yaho o.com schrieb:
The following line in my code is failing because sys.stdin.encod ing is
Null. This has only started happening since I started working with
Pydef in Eclipse SDK. Any ideas?

uni=unicode(wor d,sys.stdin.enc oding)

That's a problem with pydev, where the standard machinery to determine
the terminal's encoding fail.

I have no idea yet how to fix this.
Environmental variable TERMENCODING ? Heck, maybe this will catch on
and will be used by other languages, libraries, terminals, etc. It's
not really Python only problem.

-- Leo

Dec 11 '06 #8
Leo Kislov schrieb:
Environmental variable TERMENCODING ? Heck, maybe this will catch on
and will be used by other languages, libraries, terminals, etc. It's
not really Python only problem.
I also considered environment variables. This can likely be made
available only in 2.6, though.

Plus, in the Eclipse case, we can't know for sure that stdout
really goes to the terminal - as it is just a pipe file descriptor
(Java is not capable of managing a full pseudo-terminal).

Regards,
Martin
Dec 11 '06 #9

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

Similar topics

9
13021
by: It's me | last post by:
Why do I get an "AttributeError: read" message when I do: import sys r=sys.stdin.read() ?? I've tried: r=sys.stdin.read(80)
6
2232
by: ccdrbrg | last post by:
What is the best way to protect stdin within a library? I am writing a terminal based program that provides plugin capability using the dlopen() API. Sequencing program commands (typed) and library input prompts will not happen if stdin is supplied by pipe or redirection. So, I would like to include a statement in the pluggin
2
5071
by: velle | last post by:
My headache is growing while playing arround with unicode in Python, please help this novice. I have chosen to divide my problem into a few questions. Python 2.3.4 (#1, Feb 2 2005, 12:11:53) on linux2 1) Does " >>>print 'hello' " simply write to sys.stdout?
8
3771
by: comp.lang.php | last post by:
<? error_reporting(E_ALL & ~E_NOTICE); if (@is_file('functions.inc.php')) require_once('functions.inc.php'); $xml = preg_replace('/(>)+(<)/', '$1$2', @file_get_contents('php://stdin')); $parser = @xml_parser_create(); @xml_parse_into_struct($parser, $xml, $xmlArray, $tags); @xml_parser_free($parser); for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) {
1
3883
by: BenjaMinster | last post by:
I want to read and write unicode on stdin and stdout. I can't seem to find any way to force sys.stdin.encoding and sys.stdout.encoding to be utf-8, so I've got the following workaround: import codecs, sys out = codecs.getwriter("utf-8")(sys.stdout) def tricky(): return sys.stdin.readline().decode("utf-8"). That is, I wrap sys.stdout in a utf-8 writer and I read utf-8 input
1
5182
by: yc | last post by:
I have a encoding problem during using of subprocess. The input is a string with UTF-8 encoding. the code is: tokenize = subprocess.Popen(tok_command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,close_fds=True,shell=True) (tokenized_text,errs) = tokenize.communicate(t)
5
2687
by: Antimon | last post by:
Hi, I'm new to c/c++ and working on string stuff with visual studio 2005. I'm trying to understand something, for example when i do this: wstring st; wcin >st; if the input is pure ascii, then everything is ok, but if there are unicode characters like "ÅŸ" (u+015f) what is the encoding of st now?
7
6156
by: Markus Mayer | last post by:
Hi folks. I'm somewhat new to *nix programming and just ran into a problem. I have to take user input from the terminal but like to constrain that to some rules given, i.e. "numbers only" or "alphanumeric only" etc. scanf would do, but I don't like the fact that wrong ('disallowed') characters are visible and all that stuff. For that I need unbuffered input. Since there seems to be no atomic function to do that I tried to fiddle around...
5
5936
by: dave_140390 | last post by:
Hi, I have problems getting my Python code to work with UTF-8 encoding when reading from stdin / writing to stdout. Say I have a file, utf8_input, that contains a single character, é, coded as UTF-8: $ hexdump -C utf8_input 00000000 c3 a9
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.