Re: Where is the problem?
RD wrote: > In article , cousinstan...@gmail.com says... > > [snip] > >> I have a couple of postscript saving examples >> that include the following geometry parameters >> which produce .ps files that render the same >> as the canvas drawings when viewed in ghostsript. > >> retval = canvas.postscript( >>file = "image/ps/xyzzy.ps , >>height = 400 , >>width = 400 , >>pagewidth = 400 , >>pageheight = 400 , >>colormode = "color" ) > > [snip] > > Wow! It worked! Thankyouthankyouthankyou. > > RD You're welcome You're Welcome You're Welcome -- Stanley C. Kitching Human Being Phoenix, Arizona -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is the problem?
In article , cousinstan...@gmail.com says... [snip] > I have a couple of postscript saving examples > that include the following geometry parameters > which produce .ps files that render the same > as the canvas drawings when viewed in ghostsript. > retval = canvas.postscript( >file = "image/ps/xyzzy.ps , >height = 400 , >width = 400 , >pagewidth = 400 , >pageheight = 400 , >colormode = "color" ) [snip] Wow! It worked! Thankyouthankyouthankyou. RD -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is the problem?
RD wrote: > Python 3.4.3 on WinXP. > > I create a Tk canvas and draw on it with create_text(), > create_line(), and create_polygon with fill and stipple. > > So far, so good, looks fine on the screen. > > So I go to send it to a postsctript file: > > bmap.postscript(file="tmp.ps", colormode='color') > > It generates a file, no errors reported. > > So I open up the file in a PS viewer (2, actually), > and the saved file looks like someone left a > watercolor out in the rain. > > Artifacts everywhere, the lines are blurred, and the > text is unreadable. > > Googling was unhelpful; did I miss something? > > TIA I have a couple of postscript saving examples that include the following geometry parameters which produce .ps files that render the same as the canvas drawings when viewed in ghostsript. retval = canvas.postscript( file = "image/ps/xyzzy.ps , height = 400 , width = 400 , pagewidth = 400 , pageheight = 400 , colormode = "color" ) Perhaps adding the geomerty parameters might help. -- Stanley C. Kitching Human Being Phoenix, Arizona -- https://mail.python.org/mailman/listinfo/python-list
Where is the problem?
Python 3.4.3 on WinXP. I create a Tk canvas and draw on it with create_text(), create_line(), and create_polygon with fill and stipple. So far, so good, looks fine on the screen. So I go to send it to a postsctript file: bmap.postscript(file="tmp.ps", colormode='color') It generates a file, no errors reported. So I open up the file in a PS viewer (2, actually), and the saved file looks like someone left a watercolor out in the rain. Artifacts everywhere, the lines are blurred, and the text is unreadable. Googling was unhelpful; did I miss something? TIA -- https://mail.python.org/mailman/listinfo/python-list
Re: Subclass str: where is the problem?
Hi Pascal, Indeed, the example you show work corrctly. But in the code you posted before, you wonder about the behavior of these lines: > m = MyObject() > m.id > '' > type(m.id) > So what happens when you provide the empty string '' to your and-or construct? value = '' value = type(value) is type('') and Upper(value) or value As you can easily check, bool('') resolves to False. Thus, your line becomes: value = False and False or value Python first evaluates the and expression, which resolves to False. The or expression evaluates the second argument and returns that one as the result if and only if the first one evaluates to False, which is the case here. So the result of False or value is value. You can check that >>> value is (False or value) True so, in you code, the empty string gets indeed assign as value again. Be carefull with the condition/and/or chain! You must be 110% sure, that the desired return value in case of condition==True can never evaluate to False! - harold - -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclass str: where is the problem?
Effectively. Thanks a lot Peter and Harold. -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclass str: where is the problem?
[EMAIL PROTECTED] wrote: > This is good... try this: > > value = 'test' > value > 'test' > type(value) > > value = type(value) is type('') and Upper(value) or value > value > 'TEST' > type(value) > Try again with value = "" This makes Upper(value) a False value in a boolean context: >>> class Upper(str): ... pass ... >>> Upper("") '' >>> type(Upper("")) >>> type(Upper("") or "") versus >>> type(Upper("x") or "x") Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclass str: where is the problem?
This is good... try this: value = 'test' value 'test' type(value) value = type(value) is type('') and Upper(value) or value value 'TEST' type(value) value = 1 value 1 type(value) value = type(value) is type('') and Upper(value) or value value 1 type(value) -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclass str: where is the problem?
[EMAIL PROTECTED] schrieb: > Hello, can anybody explain/help me: > > Python 2.4.2 (#2, Sep 30 2005, 21:19:01) > [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2 > > > class Upper(str): > def __new__(cls, value): > return str.__new__(cls, value.upper()) > > u = Upper('test') > u > 'TEST' > type(u) > > u = Upper('') > u > '' > type(u) > > > > All seems to be ok... > > class MyObject(object): > def __init__(self, dictionary = {}): > self.id = dictionary.get('id', '') > def __setattr__(self, attribute, value): > value = type(value) is type('') and Upper(value) or value > object.__setattr__(self, attribute, value) > > m = MyObject({'id': 'test'}) > m.id > 'TEST' > type(m.id) > > m = MyObject() > m.id > '' > type(m.id) > > > Why is m.id a str ? Because Upper(value) will be False in the line > value = type(value) is type('') and Upper(value) or value and thus, you assign value itself to value again. rewrite it for exmaple in this way: def __setattr__(self, attribute, value): if type(value) is type('') : value = Upper(value) object.__setattr__(self, attribute, value) -- http://mail.python.org/mailman/listinfo/python-list
Subclass str: where is the problem?
Hello, can anybody explain/help me: Python 2.4.2 (#2, Sep 30 2005, 21:19:01) [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2 class Upper(str): def __new__(cls, value): return str.__new__(cls, value.upper()) u = Upper('test') u 'TEST' type(u) u = Upper('') u '' type(u) All seems to be ok... class MyObject(object): def __init__(self, dictionary = {}): self.id = dictionary.get('id', '') def __setattr__(self, attribute, value): value = type(value) is type('') and Upper(value) or value object.__setattr__(self, attribute, value) m = MyObject({'id': 'test'}) m.id 'TEST' type(m.id) m = MyObject() m.id '' type(m.id) Why is m.id a str ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list