How to get a "screen" length of a multibyte string?

2012-11-25 Thread kobayashi
Hello,

Under platform that has fixed pitch font,
I want to get a "screen" length of a multibyte string

--- sample ---
s1 = u"abcdef"
s2 = u"あいう" # It has same "screen" length as s1's.
print len(s1)  # Got 6
print len(s2)  # Got 3, but I want get 6.
--

Abobe can get a "character" length of a multibyte string.
Is there a way to get a "screen" length of a multibyte string?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Chris Angelico
On Sun, Nov 25, 2012 at 9:19 PM, kobayashi  wrote:
> Hello,
>
> Under platform that has fixed pitch font,
> I want to get a "screen" length of a multibyte string
>
> --- sample ---
> s1 = u"abcdef"
> s2 = u"あいう" # It has same "screen" length as s1's.
> print len(s1)  # Got 6
> print len(s2)  # Got 3, but I want get 6.
> --
>
> Abobe can get a "character" length of a multibyte string.
> Is there a way to get a "screen" length of a multibyte string?

What do you mean by screen length? Do you mean the length in bytes?
That depends on your encoding. Do you mean width of the displayed
version? That depends on your font.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Hans Mulder
On 25/11/12 11:19:18, kobayashi wrote:
> Hello,
> 
> Under platform that has fixed pitch font,
> I want to get a "screen" length of a multibyte string
> 
> --- sample ---
> s1 = u"abcdef"
> s2 = u"あいう" # It has same "screen" length as s1's.
> print len(s1)  # Got 6
> print len(s2)  # Got 3, but I want get 6.
> --
> 
> Abobe can get a "character" length of a multibyte string.
> Is there a way to get a "screen" length of a multibyte string?

How about:

from unicodedata import east_asian_width

def screen_length(s):
return sum(2 if east_asian_width(c) == 'W' else 1 for c in s)


Hope this helps,

-- HansM
-- 
http://mail.python.org/mailman/listinfo/python-list


How to pass class instance to a method?

2012-11-25 Thread ALeX inSide
How to "statically type" an instance of class that I pass to a method of other 
instance?

I suppose there shall be some kind of method decorator to treat an argument as 
an instance of class?

Generally it is needed so IDE (PyCharm) can auto-complete instance's methods 
and properties.

Pseudo-python-code example:

i = MyClass()

xxx(i, 1, 2);

...
def xxx(self, MyClass myclass, number, foobar):
   myclass.classsmethod() #myclass - is an instance of known class
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10 sec poll - please reply!

2012-11-25 Thread ALeX inSide
press_keys()

On Tuesday, November 20, 2012 2:18:38 PM UTC+2, Michael Herrmann wrote:
> Hi, 
> 
> 
> 
> I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> having difficulty picking a name for the function that simulates key strokes. 
> I currently have it as 'type' but that clashes with the built-in function. 
> Example uses of 'type': 
> 
> 
> 
> type(ENTER)
> 
> 
> 
> type("Hello World!")
> 
> 
> 
> type(CTRL + 'a')
> 
> 
> 
> What, in your view, would be the most intuitive alternative name?
> 
> 
> 
> Here are my thoughts so far: I could call it 'press' but then our GUI 
> automation tool also allows you to click things and then "press" might be 
> mistaken for "pressing a button". A less ambiguous alternative is "type_keys" 
> but that is rather long and doesn't read as well, for instance in 
> type_keys(ENTER).
> 
> 
> 
> Thank you very much!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass class instance to a method?

2012-11-25 Thread Steven D'Aprano
On Sun, 25 Nov 2012 04:11:29 -0800, ALeX inSide wrote:

> How to "statically type" an instance of class that I pass to a method of
> other instance?

Please explain what you mean by this.

What do you think "statically type" means?


> I suppose there shall be some kind of method decorator to treat an
> argument as an instance of class?


Python does not allow you to lie about the type of an argument. All 
objects are strongly typed. If an object is a Spam instance, it is a Spam 
instance, you can't pretend that it is a Cheese instance.[1]



> Generally it is needed so IDE (PyCharm) can auto-complete instance's
> methods and properties.
> 
> Pseudo-python-code example:
> 
> i = MyClass()
> 
> xxx(i, 1, 2);
> 
> ...
> def xxx(self, MyClass myclass, number, foobar):
>myclass.classsmethod() #myclass - is an instance of known class


I do not understand what you are saying here. Please try to explain more 
carefully.






[1] You cannot lie about the type of an instance, but sometimes you can 
actually change its type. Use this feature with care, since it rarely is 
useful.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Steven D'Aprano
On Sun, 25 Nov 2012 22:12:33 +1100, Chris Angelico wrote:

> On Sun, Nov 25, 2012 at 9:19 PM, kobayashi  wrote:
>> Hello,
>>
>> Under platform that has fixed pitch font, I want to get a "screen"
>> length of a multibyte string
>>
>> --- sample ---
>> s1 = u"abcdef"
>> s2 = u"あいう" # It has same "screen" length as s1's. print len(s1)  # Got
>> 6
>> print len(s2)  # Got 3, but I want get 6. --
>>
>> Abobe can get a "character" length of a multibyte string. Is there a
>> way to get a "screen" length of a multibyte string?
> 
> What do you mean by screen length? Do you mean the length in bytes? That
> depends on your encoding. Do you mean width of the displayed version?
> That depends on your font.

That's what I thought, but on doing some experimentation in my terminal, 
and doing some googling, I have come to the understanding that so-called 
monospaced (fixed-width) fonts may support *double column* characters as 
well as single column.

So the OP's example has:

s1 = u"abcdef"
s2 = u"あいう"

s1 has six single-column ("narrow") characters, while s2 has three double-
column ("wide") characters, and both strings should take up the same 
horizontal space on screen.

If you are reading this in a non-monospaced font, the width of each 
character is not fixed, the idea of columns doesn't really work, and the 
strings may not be the same width.

See http://www.unicode.org/reports/tr11/tr11-19.html for more detail.


Interestingly, Unicode supports wide versions of many non-EastAsian 
characters (presumably because pre-Unicode EastAsian encodings supported 
them). For example, run this code in Python:

print u'\N{FULLWIDTH LATIN CAPITAL LETTER A}'; print u'AA'

which should output:

A
AA

If your font supports this, you should see a single "A" as wide as the 
double "AA" beneath it. 

Curiously, in the monospaced font I am using to type this, the 
"fullwidth" (wide, two-column) A is actually 2/3rds the width of the 
standard ("halfwidth", narrow, one-column) A. Font designers -- can't 
live with them, can't take them out and shoot them.


Hans Mulder's suggestion:

from unicodedata import east_asian_width

def screen_length(s):
return sum(2 if east_asian_width(c) == 'W' else 1 for c in s)


is almost right. The Unicode document above states:

[quote]
In a broad sense, wide characters include W, F, and A (when in East Asian 
context), and narrow characters include N, Na, H, and A (when not in East 
Asian context).
[end quote]

from unicodedata import east_asian_width
def columns(s, eastasian_context=True):
if eastasian_context:
wide = 'WFA'
else:
wide = 'WF'
return sum(2 if east_asian_width(c) in wide else 1 for c in s)


ought to do it for all but the most sophisticated text layout 
applications. For those needing much more sophistication, see here:


http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10 sec poll - please reply!

2012-11-25 Thread Michael Herrmann
On Sunday, November 25, 2012 12:23:13 AM UTC+1, Dennis Lee Bieber wrote:
> ...
>   Pardon? In ASCII (and encodings that share the first 128 positions),
> 
> a TAB is x09.
> 
> 
> 
> >>> def show(c):
> 
> ... print "%r is 0x%2.2X" % (c, ord(c))
> 
> ...
> 
> >>> show(raw_input()[0])
> 
> i
> 
> 'i' is 0x69
> 
> >>> show(raw_input()[0])
> 
> 
> 
> '\t' is 0x09
> 
> >>>
> 
> 
> 
>   My "input" for the second was 
> 
> 
> 
>   Typically, keyboard/console interfaces generate
> 
>  - 0x60 when the control key is held down.
> 
> Lowercase "i" is 0x69; minuse 0x60 give 0x09, which is the TAB
> 
> character.
> 
> 
> 
>   A GUI interface, however, may capture the combination for some other
> 
> usage.

Thanks! I did not know that.

Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10 sec poll - please reply!

2012-11-25 Thread Michael Herrmann
On Sunday, November 25, 2012 4:56:49 AM UTC+1, Steven D'Aprano wrote:
> Michael, please trim your replies. There is no need to quote nearly 200 
> lines of previous emails that you don't make direct reference to in your 
> response. We prefer inline quoting here (where you interleave quoted text 
> with the direct response to that quote), but if you must top-post or 
> bottom-post, please trim.

Sorry - I'm using the Web interface for Google Groups and it hides the quoted 
previous emails from me. I will take care in the future. 

> Also, please stop sending two copies of every post: you can send an email 
> to [email hidden], or you can post a news message to the 
> newsgroup comp.lang.python, but don't do both. You're just flooding both 
> places with two copies  of everything you say.

Same - the Google groups web interface sometimes did that by default. I'll 
double check the recipients in the future. I'm sorry!

Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread kobayashi
Encoding is utf-8.
I use "screen length" means as that; that of ascii character is 1, and that of 
character having double width than ascii character is 2.
It's not bytes, but drawing width.
As you say, it depends font. I'll be considering carefully.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread kobayashi
Great, It's a just good solution. I use it.

Thanks,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread kobayashi
I'm greateful for more detailed information and better code.
I learned a lot and I use it.

Thanks,
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: unicode 0.9.7

2012-11-25 Thread garabik-news-2005-05
unicode is a simple python command line utility that displays 
properties for a given unicode character, or searches 
unicode database for a given name. 


It was written with Linux in mind, but should work almost everywhere 
(including MS Windows and MacOSX), UTF-8 console is recommended. 

˙pɹɐpuɐʇs əpoɔı̣uՈ əɥʇ ɟo əsn pəɔuɐʌpɐ 
puɐ səldı̣ɔuı̣ɹd əɥʇ ɓuı̣ʇɐɹʇsuoɯəp looʇ ɔı̣ʇɔɐpı̣p ʇuəlləɔxə uɐ sı̣ ʇI 
˙sʇuı̣odəpoɔ ʇuəɹəɟɟı̣p ʎləʇəldɯoɔ ɓuı̣sn əlı̣ɥʍ 'sɥdʎlɓ ɟo ɯɐəɹʇs ɹɐlı̣ɯı̣s 
ʎllɐnsı̣ʌ  oʇuı̣ ʇxəʇ əɥʇ ʇɹəʌuoɔ oʇ pɹɐpuɐʇs əpoɔı̣uՈ əɥʇ ɟo ɹəʍod llnɟ 
əɥʇ sʇı̣oldxə ʇɐɥʇ 'ʎʇı̣lı̣ʇn ,əpoɔɐɹɐd, oslɐ suı̣ɐʇuoɔ əɓɐʞɔɐd əɥ⊥ 


Changes since previous versions: 

 * add option to recognise binary input numerical codes
 * do not throw an exception when run under an undefined locale
 * on error, exit with nonzero existatus
 * preliminary python3 support
 * other minor tweaks and improvements


URL: 
http://kassiopeia.juls.savba.sk/~garabik/software/unicode/

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Migrate from Access 2010 / VBA

2012-11-25 Thread Wolfgang Keller
> I am the lone developer of db apps at a company of 350+ employees.
> Everything is done in MS Access 2010 and VBA. I'm frustrated with the
> limitations of this platform and have been considering switching to
> Python.
>
> I've been experimenting with the language for a year or so,
> and feel comfortable with the basics. 
> 
> I am concerned that I'll have a hard time replacing the access form
> and report designers. I've worked a little with TKinter, but it's a
> far cry from the GUI designer in Access.

The list of Python frameworks for rapid development of desktop 
(i.e. non-Web) database applications currently contains: 

using PyQt (& Sqlalchemy): 
Pypapi: www.pypapi.org 
Camelot: www.python-camelot.com 
Qtalchemy: www.qtalchemy.org 

using PyGTK: 
Sqlkit: sqlkit.argolinux.org (also uses Sqlalchemy) 
Kiwi: www.async.com.br/projects/kiwi 

using wxPython: 
Dabo: www.dabodev.com 
Defis: sourceforge.net/projects/defis (Russian only) 
GNUe: www.gnuenterprise.org 

Pypapi, Camelot, Sqlkit and Dabo seem to be the most active and best 
documented/supported ones. 

> Finding a professional grade report designer looks like an even
> bigger challenge.

LibreOffice is imho quite useful for database reporting. It comes with a
native (SDBC) driver for PostgreSQL and allows Python scripting.
LibreOffice Base can even be useful for CRUD GUIs.
 
> I don't need to port any applications, but I will need to use the
> data (mdb/accede format),

Don't. Put your data into an *actually* transaction-safe RDBMS (which
"Jet" is *not*), such as e.g. PostgreSQL.

> design a variety of reports with multi-level groupings, and deliver
> them to many individual recipients via email.

Sincerely,

Wolfgang
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Serhiy Storchaka

On 25.11.12 12:19, kobayashi wrote:

Under platform that has fixed pitch font,
I want to get a "screen" length of a multibyte string

--- sample ---
s1 = u"abcdef"
s2 = u"あいう" # It has same "screen" length as s1's.
print len(s1)  # Got 6
print len(s2)  # Got 3, but I want get 6.
--

Abobe can get a "character" length of a multibyte string.
Is there a way to get a "screen" length of a multibyte string?


http://bugs.python.org/issue12568

--
http://mail.python.org/mailman/listinfo/python-list


Direct Client is looking for two C/C++ Developer in Germantown MD for longterm contract.

2012-11-25 Thread sush@AjelTechnologies
Dear Partner,

Hope you are doing well.

I am a Resource Specialist working for a rapidly growing IT Services
company 'Ajel Technologies'. We have a current opportunity which might
be interest for you or your consultant. We are looking for a candidate
with 7 plus years of experience in C / C++ as a Developer in
Germantown MD. Please send your updated resume along with expected
rate and contact details at your earliest to am18 (at) ajel (dot) com.

Title: Java C/C# Developer
Location: Germantown MD
Duration: 6 Months Contract (Possible to extend)
Start Date: ASAP
No of positions: 2
Direct End Client: XEROX

Preferred / Desired:
Bachelors degree in Computer Science or equivalent.
5 to 7 years experience in OO design and C/C++ development
C/C++; PL/SQL; Stored procedures
Good understanding of data modeling and object oriented concepts
Excellent written and verbal communication skills
Ability to multi-task across numerous activities
background in large scale transaction processing and financial
management systems.
Expertise in developing high volume transaction processing
applications, application-to-application integration, real-time
transaction processing and message queuing.
Experience working in a team environment where team members are
geographically dispersed.
Client interaction and presentation skills.
Experience with PL/SQL Editor, ETL tools a plus
Large scale data migration experience a plus
Oracle experience a plus
JMS and MQ experience a plus

Education and Typical Years Experience
BA / BS degree that is relevant to the position.
7+ years of hands-on software development experience in C/C++
programming.

Required:
7+ years of hands-on software development experience.
Work in a structured environment designing and developing java-based,
enterprise class J2EE application solutions
Contribute to detailed design documentation (component diagrams,
sequence diagrams, etc.)
Review high-level and detailed designs for accuracy and completeness
Translate use cases, sequence diagrams, class diagrams into source
code.
Work with QA/Test team to resolve deficiencies
background with systems operating in a 24x7 production environment.
Experience in scripting and using source code control systems.
Analysis and design skills using formal methodologies and Object
Oriented Programming principles.
Relational database experience, Oracle preferred.
Demonstrated ability to meet schedules and multi-task.
Outstanding oral and written communications skills in both technical
and client facing situations.
Ability to check ones ego at the door. Individual must be a team
player, receptive to new ideas and concepts and willing to embrace
them when final determinations are made.

** Please ignore the email in case you are not interested / over
qualified *** Contact me directly for other positions country wise. We
have openings with our clients throughout the country that might match
your job title and skills. I am here to help you in getting your dream
job.

If you are available and interested please forward your Resume to me
am18 (at) ajel (dot) com or  please call me ASAP at (732) 476-6023. If
you do respond via e-mail please include a daytime phone number so I
can reach you. If you are not interested, kindly refer anyone who
would be interested. We offer great referrals!

Thank you in advance!

Sincerely yours,
AM18-Sushma Patnaik
a...@ajel.com
(732) 476-6023
Ajel Technologies Inc
www.ajel.com
http://www.linkedin.com/in/sushmajel

Note: Please allow me to reiterate that I chose to contact you either
because your resume had been posted to one of the internet job sites
to which we subscribe, or you had previously submitted your resume to
Ajel. I assumed that you are either looking for a new employment
opportunity, or you are interested in investigating the current job
market.
If you are not currently seeking employment, or if you would prefer I
contact you at some later date, please indicate your date of
availability so that I may honor your request. In any event, I
respectfully recommend you continue to avail yourself to the
employment options and job market information we provide with our e-
mail notices.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: only .exe

2012-11-25 Thread bakie
how to make to complie my python code ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: only .exe

2012-11-25 Thread bakie
ha !!!

Is it not complie ?
plz see bro / woman 

http://effbot.org/zone/python-compile.htm

how to make only excutable file for python code ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass class instance to a method?

2012-11-25 Thread Gregory Ewing

ALeX inSide wrote:
I suppose there shall be some kind of method decorator to treat an argument as an 

> instance of class?

You can do this:

   xxx = MyClass.some_method

and then

   i = MyClass()
   xxx(i, foo, bar)

Does that help?

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: only .exe

2012-11-25 Thread Steven D'Aprano
On Sun, 25 Nov 2012 14:09:49 -0800, bakie wrote:

> how to make to complie my python code ?

python -m compileall filename.py


If this does not answer your question, please explain your question more 
carefully. We are not mind-readers, we cannot tell what you are thinking, 
only what you post.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Evan Driscoll

On 11/25/2012 07:48 AM, kobayashi wrote:

Encoding is utf-8.
I use "screen length" means as that; that of ascii character is 1, and that of 
character having double width than ascii character is 2.
It's not bytes, but drawing width.
As you say, it depends font. I'll be considering carefully.



Don't forget also that there are combining characters. To wit:

>>> "\u00e1"
'á'
>>> "\u0061\u0301"
'á'

(U+00e1 is an 'a' with acute accent; U+0061 is an unaccented 'a'; U+0301 
is an combining acute accent.)



So far the discussion has been on single Unicode code points which 
appear as a double-wide glyph (I did not know about those!); depending 
on how you want to look at it, combining characters result in sequences 
of Unicode code points which result in a single glyph, or combining 
characters are zero-width code points.


Evan

--
http://mail.python.org/mailman/listinfo/python-list


Convert tuples into string

2012-11-25 Thread Smaran Harihar
Hi Guys,

I am connecting to postgres database and fetching the table names but it
seems that they are being returned in 

How can I convert them to string?

-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert tuples into string

2012-11-25 Thread Cameron Simpson
On 25Nov2012 19:09, Smaran Harihar  wrote:
| I am connecting to postgres database and fetching the table names but it
| seems that they are being returned in 
| 
| How can I convert them to string?

Please show:

  - the code fetching the names; we do not know what library you are
using or how your are asking for the table names

  - the tuple itself you get back

Printing repr(the-tuple-you-got-back) should present something
meaningful.

I'd imagine it is just a tuple of table name strings, but really I have
no idea from what you have said.

Cheers,
-- 
Cameron Simpson 

What's the point of having Nebraska if we can't put it to its highest and
best use?   - Patrick Bedard arguing for a 100 mph speed limit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert tuples into string

2012-11-25 Thread Smaran Harihar
I was able to solve it using the following loop,

conn=psycopg2.connect(connstr)
cursor=conn.cursor()
cursor.execute("SELECT tablename FROM pg_tables where tablename like '%"+
inp +"%'")
 records = cursor.fetchall()
str=""
for rec in records:
 if str == "":
str="".join(rec)
else:
 m="".join(rec)
str=str+","+m

Thanks,
Smaran

On Sun, Nov 25, 2012 at 7:09 PM, Smaran Harihar wrote:

> Hi Guys,
>
> I am connecting to postgres database and fetching the table names but it
> seems that they are being returned in 
>
> How can I convert them to string?
>
> --
> Thanks & Regards
> Smaran Harihar
>
>


-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert tuples into string

2012-11-25 Thread Tim Chase
On 11/25/12 20:24, Smaran Harihar wrote:
> I was able to solve it using the following loop,
> 
> conn=psycopg2.connect(connstr)
> cursor=conn.cursor()
> cursor.execute("SELECT tablename FROM pg_tables where tablename like '%"+
> inp +"%'")
>  records = cursor.fetchall()
> str=""
> for rec in records:
>  if str == "":
> str="".join(rec)
> else:
>  m="".join(rec)
> str=str+","+m

Sounds like you want the first element of the tuple which you can
access either as "row[0]" or by unpacking the tuple into a
one-element tuple.  The first would look something like

  cursor.execute(...)
  s = ",".join(rec[0] for rec in cursor.fetchall())

while the second would look something like

  cursor.execute(...)
  s = ",".join(tablename for (tablename,) in cursor.fetchall())

Note that I'm directly building the string with .join rather than
appending (the growth of which has bad performance in Python).

-tkc


-- 
http://mail.python.org/mailman/listinfo/python-list