473,657 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python, Unicode, Excel and Web Tesing

Hello,

I have been doing some experimenting with Automating Internet Explorer
for testing.

I would like to read from Excel and use the data to set the values of
my text boxes on my web forms.
I have been running into problems with Unicode as I can see others
have too.
I have seemed to find a simple solution when printing

Since Excel seems to give back this format (u'Test1',)

If I use this code I get
(u'Test1',)
(u'Test2',)
(u'Test3',)
(u'Test4',)
(u'Test5',)
############### ############### ############
import win32com.client .dynamic

x = win32com.client .dynamic.Dispat ch("Excel.Appli cation")
x.Visible=0
x.Workbooks.Ope n("C:\\Python23 \\Lib\\site-packages\\test. xls")
val = x.Range("A2:A20 ").Value
for i in val:
print i #Prints the unicode charaters

############### ############### ############

If I use the code below it works fine.
Test1
Test2
Test3
Test4
Test5

############### ############### ############
import win32com.client .dynamic

x = win32com.client .dynamic.Dispat ch("Excel.Appli cation")
x.Visible=0
x.Workbooks.Ope n("C:\\Python23 \\Lib\\site-packages\\test. xls")
val = x.Range("A2:A20 ").Value
for i in val:
print i [-1] #Prints without the unicode charaters

############### ############### ############

Does anyone esle ot there have any experience in Automating IE in
Python and using Excel Data?
I am new Python programming but I have managed to write several
functions for Automation I.E.
for setting text values, setting listboxes, links, Clicking buttons
ect. that are working fine.

I am working on porting another tool SAM (written in Perl)
http://samie.sourceforge.net to Python

I would like to share the info on this with other who might have
Automated Internet Explorer with Python.

Thanks
R.
Jul 18 '05 #1
3 3636
ca*****@yahoo.c om wrote:

[problems with excel automation, reportedly due to unicode]

(u'Test1',)

is a tuple, you are doing

(u'Test1',)[-1]

to extract the last item in that tuple, which is, by the way, the same as
the first item (u'Test1',)[0] in this case.

So you may still run into trouble when you inadvertently try to convert your
unicode string into a str *and* it contains characters with ord(c) >= 128.

However, rest assured that Python will spit out a helpful traceback :-)

Peter

Jul 18 '05 #2
ca*****@yahoo.c om writes:
[...]
I have been running into problems with Unicode as I can see others
have too.
I have seemed to find a simple solution when printing

Since Excel seems to give back this format (u'Test1',)

If I use this code I get
(u'Test1',)
(u'Test2',)
(u'Test3',)
(u'Test4',)
(u'Test5',) [...] for i in val:
print i #Prints the unicode charaters
These are length-1 tuples containing unicode strings.
[...] If I use the code below it works fine.
Test1
Test2
Test3
Test4
Test5 [...] for i in val:
print i [-1] #Prints without the unicode charaters


These are unicode strings. Why no u'' business? First, you need to
know that str()'s job is to print readable strings. repr(obj)'s job
is to print a string such that when you eval() it, you get back the
same thing you started out with:
text = repr(u'foo')
eval(text) u'foo'
ie. repr(u'foo') == "u'foo'"
whereas str(u'foo') == "foo"

Now, print obj prints str(obj), but str(sequence) typically returns a
string containing the repr() of every item in the sequence, NOT the
str() of every item in the sequence. Hence:
str(u'foo') 'foo' str((u'foo',)) "(u'foo',)"

John
Jul 18 '05 #3
Peter Otten <__*******@web. de> wrote in message news:<bo******* ******@news.t-online.com>...
ca*****@yahoo.c om wrote:

[problems with excel automation, reportedly due to unicode]

(u'Test1',)

is a tuple, you are doing

(u'Test1',)[-1]

to extract the last item in that tuple, which is, by the way, the same as
the first item (u'Test1',)[0] in this case.

So you may still run into trouble when you inadvertently try to convert your
unicode string into a str *and* it contains characters with ord(c) >= 128.

However, rest assured that Python will spit out a helpful traceback :-)

Peter


Thanks Peter for the feedback!!
Jul 18 '05 #4

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

Similar topics

6
3779
by: Chris | last post by:
hi, to convert excel files via csv to xml or whatever I frequently use the csv module which is really nice for quick scripts. problem are of course non ascii characters like german umlauts, EURO currency symbol etc. the current csv module cannot handle unicode the docs say, is there any workaround or is unicode support planned for the near future? in most cases support for characters in iso-8859-1(5) would be ok for my purposes but of...
10
3681
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. Andrew dalke@dalkescientific.com
1
4844
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was wondering if anybody has experienced the same issues
12
6012
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the examples, I found its printing of cell's contents in a different manner. print sh.row(rx)
0
263
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 431 open ( +3) / 3425 closed ( +8) / 3856 total (+11) Bugs : 916 open (-23) / 6273 closed (+44) / 7189 total (+21) RFE : 244 open ( +4) / 240 closed ( +1) / 484 total ( +5) New / Reopened Patches ______________________
0
1382
by: Steve Holden | last post by:
ganesh gajre wrote: You are getting too ambitious. Text files don't have any font information associated with them. Not only that, but the encoding of Unicode character data is independent of the font used to render the readable glyphs as text. This makes it look as though you don't really know what you are doing. Perhaps you should start more slowly, and try explaining the real problem.
0
8315
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8508
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,...
0
8608
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5633
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
4164
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...
1
2733
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 we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
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.