Re: Any speech to text conversation python library for Linux and mac box

2013-06-13 Thread Alan Gauld

On 13/06/13 04:59, Ranjith Kumar wrote:

Hello all,
I'm looking for speech to text conversation python library for linux and
mac box, I found few libraries but non of them supports any of these
platform.


This list is for people learning the python language and standard library.

If you are looking for exotic libraries you should have more success 
posting on the general Python mailing list or newsgroup (comp.lang.python)


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: Pymongo Error

2012-06-19 Thread Alan Gauld

On 19/06/12 06:22, Ranjith Kumar wrote:


I tried Django with Mongodb while running manage.py syncdb I endup with
this error


You might be better off trying a mongo forum./mailing list since this 
list is for Python beginners and focuses on the Python language and std 
library. Django is not in the standard library but is sufficiently 
common that you may get a response there. But Mongo is a wee bit 
specialised so it will be pure luck if you find a Mongo user who can 
answer...



django.db.utils.DatabaseError: Ordering can't span tables on
non-relational backends (content_type__app_label)


Given we can't actually see the command you are trying to execute
its virtually impossible to know what Mongo/Django/Python is complaining 
about. We would need to know a lot more about your data structure and 
your query. What is it you are trying to order for example? Does it span 
tables?


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



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


Re: Fall in love with bpython

2011-07-27 Thread Alan Gauld

Karim wrote:


I use bpython interpreter. This is a very good interactive CLI.


I had never heard of it and had to google for it.
It appears to be a curses based CLI for *nix and MacOS



I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...


Why not read the bpython source to see what they used?
Thats the big advantage of open source - its open!
(Although they don't make the source explicitly available,
I'm assuming the tar file contains the source- it might
even be in Python!)

They use pygments to parse the source as you type.
That would be worth investigating too...


HTH,

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


Re: Python/New/Learn

2022-05-05 Thread Alan Gauld
On 05/05/2022 02:36, Patrick 0511 wrote:
> Hello, I'm completely new here and don't know anything about python. 

Do you know any other programming languages?
That makes a huge difference in what you should start with!

> Can someone tell me how best to start? 
> So what things should I learn first?

Others have already made recommendations.

I'll add that there is a dedicated python ttutor list for
those just learning to ask questions. It is slightly more
tolerant of "silly" questions and rookie mistakes than
the main list here.

You'll also find most of the discussions there will be
closer to your level than the more advanced topics that
get addressed here.

Finally, I have a tutorial aimed at complete beginners,
see the link below...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

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


Re: an oop question

2022-10-31 Thread Alan Gauld
On 30/10/2022 14:01, Julieta Shem wrote:

> I wrote the classes
> 
>   class Empty:
> ...
>   class Pair:
> ...
> 
> (*) How to build a stack?
> 
> These Lisp-like sequences are clearly a stack.  

That is a very important observation. A Pair IS-A Stack(sort of).
If you had a stack you could create a Pair from it certainly.

> So far so good, but when it comes to building a better user interface
> for it I have no idea how to do it.  I think one of the purposes of OOP
> is to organize code hierarchically so that we can reuse what we wrote.

One of the purposes of classes certainly. I'm not so sure it's a purpose
of OOP. They are not the same thing. A class is a programming construct
OOP is a programming style. Classes facilitate OOP but can be used
outside of OOP too.

> So I tried to make a Stack by inheriting Pair.

But you said above that a Pair was a Stack. Inheritance implies an
IS-A relationship, so Stack inheriting Pair would mean that a Stack
was a Pair. That is not really true.

A Stack could use a Pair (or many of them) but it is not a Pair.

Trying to use inheritance inappropriately is one of the
biggest (and commonest) mistakes in OOP. It invariably leads
to complications. If in doubt use delegation instead.


> class Stack(Pair):
> pass
> 
 Stack(1, Empty())
> Stack(1, Empty())
> 
> Then I wrote pop and push.
> 
 Stack(1, Empty()).pop()
> 1
> 
 Stack(1, Empty()).push(2)
> Stack(2, Stack(1, Empty()))
> 
> So far so good.  Now let me show you what I can't do.
> 
> (*) The difficulty of encapsulating a union
> 
> The Lisp-like sequences we're building here are union-like data
> structures.  A /sequence/ is either Empty() or Pair(..., /sequence/).  I
> have not found a way to represent this either-or datastructure with a
> class.  For example, there is no way right now to build an empty Stack
> by invoking the Stack constructor.
> 
 Stack()
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: Pair.__init__() missing 2 required positional arguments: 'first' 
> and 'rest'
> 

The usual Python approach to such things is to put some default
values(often None but could be an Empty instance in your case)
in the init() method parameter list. Then test if the inputs
are None and if so take the appropriate action.

> class Pair:
>   def __init__(self, first=Empty(), rest=Empty()):

Like this.

> if not isinstance(rest, Pair) and not isinstance(rest, Empty):
>   raise ValueError("rest must be Empty or Pair")
> self.first = first
> self.rest = rest
>   def fromIterable(it):
> if len(it) == 0:
>   return Empty()
> else:
>   return Pair(it[0], Pair.fromIterable(it[1:]))
>   def __str__(self):
> return "{}({!r}, {})".format(self.__class__.__name__, self.first, 
> str(self.rest))
>   def __repr__(self):
> return str(self)
>   def __len__(self):
> return 1 + self.rest.__len__()
> 
> class Empty:
>   def __len__(self):
> return 0
>   def __str__(self):
> return  "Empty()"
>   def __repr__(self):
> return self.__str__()
>   def __new__(clss):
> if not hasattr(clss, "saved"):
>   clss.saved = super().__new__(clss)
> return clss.saved
> 
> class Stack(Pair):
>   def pop(self):
> return self.first
>   def push(self, x):
> return Stack(x, self)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: an oop question

2022-11-02 Thread Alan Gauld
On 01/11/2022 17:58, Julieta Shem wrote:

> nowhere in trying to detect in high-precision what is OOP and what is
> not. 

Stefan has given a good answer but essentially OOP is a program
that is structured around objects communicating by sending
messages to one another.

Objects are, in most (but not all) languages implemented using classes.
A class is just a record or structure that can contain data and
functions. In most (but not all) implementations of OOP messages
are implemented as calls to the functions within an objects class.


>  The same for classes.  I always liked to think of C structures as
> some class. 

Provided that we allow pointers to functions within the struct then yes.
Indeed the difference between structs and classes in C++ is very thin.

And with the recent introduction of data classes in Python the
boundaries are blurred here too. In pure OOP a class with only
data would be pointless(since the data should ideally be hidden
or "private"!)

> structure Whatever si the class itself.  Is this use of C outside of
> OOP?  I say it is not because my notion of OOP is that --- a way to make
> objects and have methods operate on them, changing them or not.

It's how many early attempts at OOP in C worked, including C++.
Others, such as Objective C and cFlavours took a different approach.

But conceptually methods do not "operate on objects"
methods are how objects respond to messages. Eah object has its own
method of handling a particular message. (This is polymorphism)
In most (but not all) practical implementations methods are
usually implemented as functions and so it seems like a message
is just a synonym for acalling a method, but is more than that, it
implies some kind of dynamic lookup. (for example when the method is
implemented in a paremt class rather than the directly referenced one.

But the functions that represent methods do indeed operate on their
own object - ie self.

> To me what distinguishes functional from imperative is, 

Not that imperative programming is not the same as OOP. Or at
least it encompasses much more than OOP. Most OOP programs are
written in imperative languages but it is possible to have
functional OOP programs too. (If we consider the state data
to be a single compound value that can only be changed by
the object internally, or a new object with different
state values returned.)

>> IS-A relationship, so Stack inheriting Pair would mean that a Stack
>> was a Pair. That is not really true.
> 
> That's another interesting observation.  I do not have much
> understanding of how to really think of these things

Read up on the Liskoff substitution principle as one approach to
determining what an IS-A relationship means. Its not the only
approach but it is less vague than some others!

>> to complications. If in doubt use delegation instead.
> 
> What is delegation?

A fancy OOP term to mean containment.
Specifically a method delegates the work top some internal
object. eg. You can build a stack by containg a list within
it. The stack delegates much of the work to the list object.
In fact, in Python a stack can be a very thin wrapper over
a list!

> Any book recomendations on getting this thing mathematics-clear?

The best book is IMHO Bertrand Meyer's book "Object Oriented
Software Construction". It uses his own language,. Eiffel, but
gives an excellent description of applied OOP and all of its
features (Eiffel is perhaps the most feature complete OOPL of
all - but, being proprietary (and somewhat buggy!) it has
never quite caught on)

But for a mathematical basis you need to look outside programming
at systems engineering and the work done on cellular automata.
In a pure OOP program each object should act as an independant
cell communicating by asynchronous messages. Exactly as in
cellular automata theory. ..

Unfortunately, there is a huge gap between pure OOP theory and
practical OOP languages! And just as big a gap between OOP language
potential and real-world OOP usage.  Very few purely OOP programs
exist (maybe excepting in Smalltalk - see Stefan's posts again). :-(

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [correction]an oop question

2022-11-02 Thread Alan Gauld
On 02/11/2022 20:21, Dennis Lee Bieber wrote:

>>  shows that in Python we do *not* need subclassing/inheritance
>>  for polymorphism!
>>
>   To me, that is not really an example of polymorphism, but more an
> example of Python's "duck typing".

But duck typing is a perfectly good implementation of polymorphism.
The term just means that different objects respond to the same
message in different ways. Nothing more, nothing less. Inheritance
just happens to be the most common way of building that, especially
in statically typed languages.

> 
>   I'd implement the example hierarchy as
> 
 class Language:
> ...   def f(self):
> ...   print(self.greeting)

And that would be perfectly valid too.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: an oop question

2022-11-03 Thread Alan Gauld
On 03/11/2022 00:25, Julieta Shem wrote:

>> |OOP to me means only messaging, local retention and protection and
>> |hiding of state-process, and extreme late-binding of all things.
> 
> I'm wondering how Python fails to satisfy his definition.

Python doesn't do any form of data protection/hiding. All
attributes are public by default.

In Smalltalk all attributes are private, with no way to
make them public... Actually in C++/Java terms I believe
they are "protected" because subclasses can access
them(I think?).

Also Python is not a purely OOP language, in that you can write
functional and procedural code in Python if you wish. In
Smalltalk thats notionally impossible because everything
is an object. And all programming statements are messages
to objects.

Even an if/else test is a message to the boolean object:

(5>3) ifTrue: 
  ifFalse: 

ifTrue is a message to the boolean result of the expression
which has a parameter of a block of code. It executes the
block if the boolean is true.
ifFalse is likewise a message to the same boolean object
but only executes its block if the boolean is false.

(Apologies if the syntax is out, its been a while since I
wrote any Smalltalk!)

Similarly loops are implemented as messages:

 whileTrue: 
 to:  do: 

So in Smalltalk absolutely everything is a message to an object.

Python by comparison is much more traditional in form.

It is possible to write procedural, non OOP code in
Smalltalk but you really have to fight the system to
do so.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: an oop question

2022-11-03 Thread Alan Gauld
On 03/11/2022 18:29, Chris Angelico wrote:
> On Fri, 4 Nov 2022 at 05:21, Julieta Shem  wrote:
>>
>> Chris Angelico  writes:
>>
>>> On Thu, 3 Nov 2022 at 21:44, Alan Gauld  wrote:
>>>> Also Python is not a purely OOP language, in that you can write
>>>> functional and procedural code in Python if you wish. In
>>>> Smalltalk thats notionally impossible because everything
>>>> is an object. And all programming statements are messages
>>>> to objects.
>>>
>>> In Python, everything is an object. Doesn't that equally mean that
>>> Python is purely OOP?
>>
>> I think Alan Gauld pointed out that even syntax is an object in
>> Smalltalk --- or was.  An if-statement in Python is not an object.
> 
> Okay, fair; although I would be highly surprised if syntax is actually
> an object 

The syntax isn't, it is a specification, but the AST certainly
is and you can instantiate it and examine it from code.

But the context here was Why *Alan Kay* doesn't include Python
with Smalltalk as being OOP. There are plenty others who would
call it so.

But as for everything being an object, that's true but it doesn't
alter the fact that the default mode of python programming is not
to structure the code as a set of communicating objects (even if
at some level everything is an object) but as a set of
hierarchical functions.

And fundamentally that's what Kay means by OOP. The program (not
the language!) is built around objects. One of the greatest
barriers to the adoption of OOP is the confusion between OOP
and OOPL. And sadly the majority of attention has been on OOPL
rather than OOP...

> the concept "pass this message to this object" an object? Is the
> message itself an object? Is it objects all the way down?

At some point you hit C/Assembler. But it is astonishing just
how far down the objects go in Smalltalk.

But the control flow etc are fully OOP as per my last message.
It if quite possible to subclass Boolean and override the
whileTrue method to do something completely different to
the normal while loop behaviour. Is it wise? No. But it
is definitely possible!

> At some point, any language with objects in it is "object oriented" to
> some extent, and after that, it's all a spectrum. 

And this is exactly the problem. In the 80s we had a fairly clean
concensus of what OOP meant and several different language approaches
to that. But when C++ became popular(the defacto standard) peple started
focussing on the language features and totally missed that Object
Oriented Programming means writing programs that consist of objects
communicating by messages. The language features(even classes) are
merely implementation details. (I suspect this was partly driven
by the fact that many university lecturers at the time didn't
really grok OOP and teaching language features was much easier
than teaching a new way of thinking about problems!)

This was compounded when someone (Booch maybe?) came up with a set
of criteria to determine whether a language was a "true OOPL" or
merely "Object Based" (Ada and VB they're looking at you!) But
frankly that was an irrelevance to OOP. You can do OOP (and I
have!) in assembler and in COBOL - you just need to follow
some agreed ground rules. It's a lot easier with an OOPL but
it's not required.

> multidimensional thing that's so tangled up that it guarantees that
> people can happily debate for years to come.
Exactly so. During the 90's there came to be at least 3 different
camps of OOP evangelists and the OOP world slowly coalesced on
a kind of hybrid amalgam with multiple names for the same feature
and disagrements about which features are required or not to
really be OOP. And as a result the whole concept of OOP has
been muddied to the point that almost nobody does it anymore
apart from (possibly) the Smalltalk crowd who have always
smugly sat above the general throng content in the knowledge
that theirs is the one true OOP! :-)

Which brings us back to Alan Kay...


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Does one have to use curses to read single characters from keyboard?

2022-12-12 Thread Alan Gauld
On 11/12/2022 21:07, dn wrote:
> On 11/12/2022 23.09, Chris Green wrote:
>> Is the only way to read single characters from the keyboard to use
>> curses.cbreak() or curses.raw()?  If so how do I then read characters,
>> it's not at all obvious from the curses documentation as that seems to
>> think I'm using a GUI in some shape or form.
>>
>> All I actually want to do is get 'Y' or 'N' answers to questions on
>> the command line.
>>
>> Searching for ways to do this produces what seem to me rather clumsy
>> ways of doing it.
> 
> You may like to re-ask this question over on the Python-Tutor list. The 
> ListAdmin over there (literally) wrote the book on Python+curses...
> 
> 
> Did such research include the keyboard module?
> https://pypi.org/project/keyboard/
> 
> This project includes an (Enter-free) "hot-key" feature which firstly 
> detects the specific key or key-combination, and then calls an action 
> if/when True.
> (amongst other functionality)
> 
> Quick read tutorial: 
> https://www.thepythoncode.com/article/control-keyboard-python
> 
> Disclaimer: have had it on my 'radar', but never actually employed.
> (if you have considered, will be interested to hear conclusions...)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Does one have to use curses to read single characters from keyboard?

2022-12-13 Thread Alan Gauld
On 12/12/2022 17:45, Alan Gauld wrote:

Absolutely nothing apparently!

But in practce I did pen some esponses to Davids post. However
this list seems to strip out what I've written, its happened
a few times now. Not every time but enough that I rarely post
here.

But I'll try once more...

> On 11/12/2022 21:07, dn wrote:
>> On 11/12/2022 23.09, Chris Green wrote:
>>> Is the only way to read single characters from the keyboard to use
>>> curses.cbreak() or curses.raw()?

>> You may like to re-ask this question over on the Python-Tutor list. The 
>> ListAdmin over there (literally) wrote the book on Python+curses...

Thanks for the plug David, but...

While my book is, I think, the only one specifically for curses with
Python, it's hardly a definitive tome on the subject, rather a
beginner's tutorial. An expanded HowTo if you like..

>> Did such research include the keyboard module?
>> https://pypi.org/project/keyboard/

There are several such modules, including a good one by Fred Lundh.
They are cross platform and probably the best solution for the
OP if he doesn't mind using a third party module. I think Fred's
was called terminal? But its been a while I normally just use curses
for anything terminal related.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: String to Float, without introducing errors

2022-12-17 Thread Alan Gauld
On 17/12/2022 11:51, Paul St George wrote:
> I have a large/long array of numbers in an external file. The numbers look 
> like this:
> 
> -64550.727
> -64511.489
> -64393.637
> -64196.763
> -63920.2

> When I bring the numbers into my code, they are Strings. To use the 
> numbers in my code, I want to change the Strings to Float type 
> because the code will not work with Strings but I do not want 
> to change the numbers in any other way.

That may be impossible. Float type is not exact and the conversion
will be the closest binary representation of your decimal number.
It will be very close but it may be slightly different when you
print it, for example. (You can usually deal with that by using
string formatting features.)

Another option is to use the decimal numeric type. That has other
compromises associated with it but, if retaining absolute decimal
accuracy is your primary goal, it might suit you better.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: NoneType List

2022-12-31 Thread Alan Gauld
On 31/12/2022 05:45, Goran Ikac wrote:

> b = a.append(3)


> I mean: why b = a.append(something) is the None type, and how to make a new
> list that contains all the items from a and some new items?

append() like many other collection methods in Python works
in place and returns None. But the action has succeeded
and 3 will have been appended to list 'a'.

So, to create a new list that contains all the old items you could do:

newlist = []   # an empty list
for item in oldlist:
newlist.append(item)

This is so common Python has a shorthand form to do this:

newlist = [item for item in oldlist]

called a list comprehension.

And there is an even shorter way using something called slicing:

newlist = oldlist[:]# copy oldlist to new.


However, as an ex-Smalltalk programmer, I do wish that Python
returned self from these methods rather than None so that
we could chain them. But sadly it doesn't.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: RE: NoneType List

2023-01-02 Thread Alan Gauld
On 02/01/2023 02:14, avi.e.gr...@gmail.com wrote:
> I used PASCAL before C and I felt like I was wearing a straitjacket at times
> in PASCAL when I was trying to write encryption/decryption functions and had
> to find ways to fiddle with bits. Similar things were easy in C, and are
> even easier in many more recent languages such as Python. 

That's true of pure Pascal. But Thomas was talking about Turbo Pascal
which had extra functions and features for all those "real world" type
things. (And you could insert some inline assembler if all else failed)
It also relaxed the ludicrously strict typing slightly. Turbo Pascal
made Pascal a joy and I still use Delphi for Windows programming today.

TP also introduced classes to Pascal (although Apple had already done
so for the Mac and Borland basically ported the syntax to the PC).

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Usenet vs. Mailing-list (was: evaluation question)

2023-01-31 Thread Alan Gauld
On 28/01/2023 21:36, Dennis Lee Bieber wrote:

>   Now -- last time I checked the gmane server says posting is prohibited.
> I used to use gmane as it retrieved directly from the mailing list 

I still use gmane but its no posting thing is a pain because responding
(or posting new stuff) is a now more complicated than before. So
I have to be very highly motivated to jump through the hoops.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: TypeError: can only concatenate str (not "int") to str

2023-02-26 Thread Alan Gauld
On 26/02/2023 00:54, Greg Ewing via Python-list wrote:
> On 26/02/23 10:53 am, Paul Rubin wrote:
>> I'm not on either list but the purpose of the tutor list is to shunt
>> beginner questions away from the main list.

I'm not sure that's why we set it up but it is
certainly a large part of our remit. But protecting newbies
from overly complex responses and covering wider topics
(beyond pure Pyhon) is also a large part of our purpose.

> There's a fundamental problem with tutor lists. They rely on
> experienced people, the ones capable of answering the questions,
> to go out of their way to read the tutor list -- something that
> is not of personal benefit to them.

In practice, the "tutors" tend to be split between folks
who inhabit both lists and those who only interact on the tutor
list. eg. I lurk here and only occasionally partake.

But the problem with this particular thread is that, if directed
to the tutor list, the OP would simply be told that "that's the
way Python works". The tutor list is not for discussing
language enhancements etc. It is purely about answering questions
on how to use the language (and standard library) as it exists.
(We also cover beginner questions about programming in general.)

So this thread is most definitely in the right place IMHO.

-- 
Alan G
Tutor list moderator


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


Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread Alan Gauld
On 02/03/2023 20:54, Ian Pilcher wrote:
> Seems like an FAQ, and I've found a few things on StackOverflow that
> discuss the technical differences in edge cases, but I haven't found
> anything that talks about which form is considered to be more Pythonic
> in those situations where there's no functional difference.

I think avoiding dunder methods is generally considered more Pythonic.

But in this specific case using isinstance() is almost always
the better option. Testing for a specific class is likely to break
down in the face of subclasses. And in Python testing for static types
should rarely be necessary since Python uses duck typing
and limiting things to a hard type seriously restricts your code.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Alan Gauld
On 04/03/2023 17:38, avi.e.gr...@gmail.com wrote:
> 
> Of course each language has commonly used idioms 
> 

That's the point, the correct term is probably "idiomatic"
rather than "pythonic" but it is a defacto standard that
idiomatic Python has become known as Pythonic. I don't
think that's a problem. And at least we aren't in the C++
situation where almost everything that was idiomatic up
until 1999 is now deemed an anti-pattern and they have
standard library modules to try and guide you to use the
"correct" idioms!

But being Pythonic is still a much more loose term and
the community less stressed about it than their C++
cousins where it has almost reached a religious fervour!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Alan Gauld
On 08/03/2023 21:56, aapost wrote:
> When making a UI there are a lot of binding/trace operations that need 
> to occur that lead to a lot of annoying 1 use function definitions. I 
> don't really see lambda use like below.

Lambdas are very common in GUI callbacks but I admit I've never seen
tuples used to create multiple expressions. That's a neat trick I
hadn't thought of and will probably use.

> Giving 2 working lambda examples using a returned tuple to accomplish 
> multiple expressions - what sort of gotchas, if any, might make the 
> following bad practice if I am missing something?

Not bad practice per-se but you are still limited to expressions, no
loops for example (although you could fake it with a list comp,
but that gets ugly fast!)

Also layout is all important here. It could get very messy to read if
indentation isn't clear. You only have to look at some Javascript code
with function definitions as arguments to functions to see how clunky
that can be.

Similarly debugging so much code passed as arguments might be an
issue - no easy way to step into the lambda.

But as an alternative to writing many typical event handlers it's
definitely a valid approach that I'll be trying.

> b = tk.Button(master=main, text="Enable")
> b.config(
>  command=lambda: (
>  e1.config(state="normal"),
>  e2.config(state="normal"),
>  e3.config(state="normal")
>  )
> )

You could of course single line that with:

b = tk.Button(master=main,
  text="Enable",
  command=lambda: (
  e1.config(state="normal"),
  e2.config(state="normal"),
  e3.config(state="normal")
  )
  )

It's not a radical change from using a lamba as a
callback but it does extend the use case to cover
a common GUI scenario.

I like it. I wish I'd thought of it years ago.
Thanks for sharing.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Fwd: Friday finking: IDE 'macro expansions'

2023-03-17 Thread Alan Gauld
Oops! I meant to send this to the group not just Dave.


 Forwarded Message 

On 16/03/2023 22:55, dn via Python-list wrote:

> Do you make use of your IDE's expansionist tendencies, and if-so, which 
> ones?

When I'm writing Java/C++/C# yes, I need all the IDE help I can get.
Netbeans or Eclipse being my tools of choice. And in my Windows days
I used Delphi and Smalltalk/V which both pretty much only exist within
their own IDEs and I used their features extensively.

When writing Python I use IDLE, or vim for bigger jobs.
IDLE does have some suggestions and auto tricks but I don't
always use them. In vim I use auto-indent and that's about it.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Fwd: Friday finking: IDE 'macro expansions'

2023-03-18 Thread Alan Gauld
On 17/03/2023 17:55, Thomas Passin wrote:

>> I used Delphi and Smalltalk/V which both pretty much only exist within
>> their own IDEs and I used their features extensively.
> 
> Back when Delphi first came out, when I first used it, I don't remember 
> any IDE; one just used a text editor.

I think you might be meaning TurboPascal, Delphi's forerunner. It just
had a compiler and text editor. But Delphi from day 1 was an IDE
designed to compete with Visual Basic. Everything was geared around the
GUI builder. You could write code outside the IDE but it was orders of
magnitude more difficult.

The Lazarus open source project is based on Delphi's IDE.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Fwd: Friday finking: IDE 'macro expansions'

2023-03-18 Thread Alan Gauld
On 18/03/2023 12:15, Peter J. Holzer wrote:

>> I think you might be meaning TurboPascal, Delphi's forerunner. It just
>> had a compiler and text editor.
> 
> I'd still classify Turbo Pascal as an IDE. It wasn't a standalone
> compiler you would invoke on source files you wrote with some other

It had both (although I'm not sure when that was introduced, the
original didn't). Mostly you used the IDE/editor but there was a
command line compiler that you could run (and a make-like project
tool too in the later versions). I started with TurboPascal on DOS
at Uni generating COM files then later used TP versions 4, 5.5(with
added OOP!) and 6 professionally, creating EXE file DOS programs.

Up until I switched to a Mac, a year ago, I still had TP6 and used
it to maintain some old TurboVision DOS programs.

But I used Delphi from version 1 through to 7(?) for all my Windows
programming and still have version 3 installed (via VirtualBox on
Linux) to keep some old shareware apps of mine running.

I often think there are a lot of similarities between
Delphi/Object Pascal and Python in the OOP area.

> it, see the errors directly in the source code. I think it even had a
> debugger which would also use the same editor window (Turbo C did).

I think the debugger came in v3, but i could be wrong. I don't
recall there being one at uni...

> Turbo Pascal predated GUIs, so it wouldn't have a GUI builder. 

No, it did have a windowing toolkit(TurboVision) but no visual UI
builder. That was the big new feature of Delphi.

> application (i.e. not a learning project) with a traditional desktop GUI
> for 20 years) so the presence or absence of a GUI builder isn't an
> essential criterion on whether something is or is not an IDE.

Indeed, but it was intrinsic to Delphi (even though you could
write non GUI apps too, but they required extra effort.)
Eclipse et al have GUI builders available as extras, in Delphi
(and Lazurus) it is hard to avoid.

BTW Delphi (v11) and the other Borland tools are still going strong,
albeit at extortionately high prices: $1000~3000 for the pro
versions!  (But there is still a free community version with
just the basics.) See http://www.embarcadero.com
And it's targeted at multi-platforms now: Windows, MacOS, Android, iOS
although it only runs on Windows.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Windows installer from python source code without access to source code

2023-03-31 Thread Alan Gauld
On 31/03/2023 13:00, Jim Schwartz wrote:
> I want a windows installer to install my application that's written in
> python, but I don't want the end user to have access to my source code.  

Others have commented that at some level it will always be thre but on a
more pragmatic level tools like py2exe bundle up a Python app as an exe
file which might be all you need?

I'm sure if a user dug deep enough they could still find the source (or
something close) but to deter casual browsing it might be what you want.

Caveat: I've never used py2exe in anger and my experiements were before
Python3 so ive no idea what it does today! But a quick check suggests it
still exists and works with python3 code - last major release was in Nov
2022.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Windows Gui Frontend

2023-04-01 Thread Alan Gauld
On 01/04/2023 18:21, Jim Schwartz wrote:
> Are there any ide’s that will let me design the screen and convert it to 
> python?  

There is nothing remotely like the VB or Delphi GUI builders.
There are some tools somewhat similar to the Java Swing and
FX GUI builders with varying degrees of bugginess.

And there are a few bespoke GUI type tools such as Dabo for
building specific types of applications.

But most Python GUI developers seem to prefer to just hard
code the Python, once you get used to it there's not much
time saving with the GUI tools.

The real time consuming stuff in building GUIs is getting
the basic design right and keeping all the controls,
keyboard bindings and menus in sync. State management
in other words.

I did a deep dive examination of GUI builders back around
v2.6 and came away less than enthused. Things may have
improved since then but I've seen no real evidence of
that.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Weak Type Ability for Python

2023-04-13 Thread Alan Gauld
On 13/04/2023 20:35, Chris Angelico wrote:

> REXX - where everything is a string,

> It was quite the experience back in the day (as OS/2's native
> scripting language), 

I briefly met REXX on a mainframe, but I did play with OS/2 for
a year or two. Back when it looked like it might be a rival to M$

OS/2 running NeXTstep now that would have been a platform
for the 90s...  both so near yet so far.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: RE: Weak Type Ability for Python

2023-04-13 Thread Alan Gauld
On 14/04/2023 00:25, avi.e.gr...@gmail.com wrote:

> Is there any concept in Python of storing information in some way, such as
> text, and implementing various ideas or interfaces so that you can query if
> the contents are willing and able to be viewed in one of many other ways?

Are you talking about something like a C union type (or a Pascal
variant record)? I'm not aware of any such feature in Python but
have often thought it would be a nice to have for the rare cases
where its useful.

> Or it may be storing text in some format but the object is willing to
> transform the text into one of several other formats when needed. The text
> may also have attributes such as whether it is in English or Hungarian or is
> mixed-language.

Or are you meaning something like an extension to the
struct module that can interpret a bytestring in any way
defined by a format string?

> basis. But do some languages have some support within the language itself?

The closest to what you seem to mean is, I think, the C union
type, at least in my experience. But you have to define all
the ways you can interpret the type up front in the type
definition.

> My reason for asking, is based on the discussion. If I want to use plus with
> an integer and a string, it may be reasonable for the interpreter to ask one
> or the other operand if they are able to be seen another way.

You can achieve that in a slightly different way in Tcl which
allows you to redefine all the operators (commands in Tcl-speak)
in the language so redefining plus is easy. Doing it based on
type is more tricky but doable.

> Unfortunately, if they BOTH are flexible, how do you decide whether to add
> them as numbers or concatenate them as strings?

Yes, that's where it becomes a designer's arbitrary choice.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: tksheet - Copy and Paste with headers

2023-04-16 Thread Alan Gauld

> 在 2023/4/15 2:33, angela vales 写道:
>> I have recently created a tkinter app and need the ability to copy and 
> paste data from tksheet table into an Excel file. 

First thanks for drawing my attention to tksheet. I've long
been desiring a decent table widget in tkinter and was on the
verge of trying to create one of my own. tksheet looks like
it will do all I need.

As to copy/paste I couldn't see any explicit mention but
it does say the underlying data is in a Tk Canvas so it may
be that copy/paste will just work, did you try it? What
happened if you paste into a text editor in the first
instance? And Excel in the second?

If all else fails you can probably write handlers and bind
to Ctrl-C and Ctrl-V to do something yourself that mimics
cut/paste.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: PyCharm's strict PEP and not so strict?

2023-04-19 Thread Alan Gauld
On 19/04/2023 10:51, Kevin M. Wilson via Python-list wrote:
>  I'm in a bit of a quandary, I want some strict syntax errors to be flagged,

OK, You might want to use a "linter" in that case because most
tools use the interpreter itself to flag syntax errors.


>  but the use of single quotes vs double quotes! 
> NOT what I need from the 'checker', you dig? 

Not really. What is the problem. Use of single versus double quotes
is straightforward - use one or the other and make sure they
match(opening and closing) You can nest one type inside the
other if you need literal quotes. And of course the same applies
to triple quotes except you can include newlines inside those.

What kind of problems are you experiencing with quotes?
If we have some specific examples we can give specific answers.

> "stones" for bull, how do I set up the kind of "checking" I want?

That's not a phrase with which I'm familiar but my guess
is you need to install a linter tool and then, possibly
configure it to flag or hide particular error/warning types
to your personal taste. Each tool is different so you
will need to read the docs on how to configure it
(and how to plumb it into your IDE).

Personally I've never felt the need for any stricter error
checking than the interpreter provides so I can't offer
anything beyond the generic suggestion to use a linter.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Python curses missing form library?

2023-04-24 Thread Alan Gauld
On 24/04/2023 17:26, Grant Edwards wrote:
> Does the Python curses support in the standard library not include
> support for the curses form library? It seems to include support for
> the panel library, but I can't find any mention of the form library.

I don't believe so. If you are building terminal based form-type
apps the best bet seems to be urwid. I haven't used it in anger
but the beginner docs I saw looked promising.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [pygettext] --package-name and --package-version unknown

2023-05-04 Thread Alan Gauld
On 04/05/2023 22:38, c.bu...@posteo.jp wrote:
> Hello,
> 
> am I right to assume that "pygettext" is part of the official Python3 
> "package"? So it is OK to aks here?
> 

No it doesn't appear to be. It is not listed in the standard library.
It is mentioned in the documentation for gettext which is part of the
standard library.

It does seem to be part of the Python i18n toolkit however.
There are extensive comments in the .py file.

https://github.com/python/cpython/tree/main/Tools/i18n/pygettext.py

> I would like to modify the header that pygettext does create in each 
> po-file.

Sorry, I've never used pygettext so can't help there.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: What to use instead of nntplib?

2023-05-16 Thread Alan Gauld
On 15/05/2023 22:11, Grant Edwards wrote:
> I got a nice warning today from the inews utility I use daily:
> 
> DeprecationWarning: 'nntplib' is deprecated and slated for removal in 
> Python 3.13
> 
> What should I use in place of nntplib?

I'm curious as to why nntplib is deprecated? Surely there are still a
lot of nntp servers around, both inside and outside corporate firewalls?
Is there a problem with the module or is it just perceived as no longer
required?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: What to use instead of nntplib?

2023-05-16 Thread Alan Gauld
On 16/05/2023 10:06, Cameron Simpson wrote:

>> I'm curious as to why nntplib is deprecated? Surely there are still a
>> lot of nntp servers around, both inside and outside corporate firewalls?
>> Is there a problem with the module or is it just perceived as no longer
>> required?
> 
> See PEP 594: https://peps.python.org/pep-0594/

Thanks Cameron.
A scary list; I must have a dozen projects from the late 90s still
live that are using many of these! I'm glad I'm retired and won't
be the one who has to fix 'em :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Silly (maybe) question re imported module(s)

2023-05-19 Thread Alan Gauld
On 19/05/2023 07:44, Grizzy Adams via Python-list wrote:

> when typed in console or editor and run with F5 (which saves before it can 
> run) 
> 
> But sometimes saved work (albeit small) when imported does not work any longer

Looks like you are using IDLE? If so, it's possible that in the original
case you had some values set from a previous run that were picked up but
when you reimport later those values are missing. It would help if you
can post any error messages since they should give clues(like name
errors for example).

Also describe how you are "importing" the modules. are you typing

>>> import mymodule

at the interactive prompt or are you using the File->Open menu
to load them into the editor? (It sounds like the latter)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Silly (maybe) question re imported module(s)

2023-05-19 Thread Alan Gauld
On 19/05/2023 13:36, Grizzy Adams wrote:

>> Looks like you are using IDLE? 
> 
> Yes
> 
> 
> From consol
> 
 import cube
 cubes
> Traceback (most recent call last):
>   File "", line 1, in 
> cubes
> NameError: name 'cubes' is not defined

You imported cube but tried to use cubes. I'm guessing
cubes is defined inside cube so you would need

cube.cubes

> File->Open mymodule.module into the editor, then F5 to run all is well
> 

>  RESTART: D:\Shades\Tools\Python\Temp\cube.py 
 cubes
> [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]


cubes looks like it should be a function but in that case there
should be parens after it. So I'm not sure how that is working!

I'd expect that you need to do:

import cube
cube.cubes()

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Silly (maybe) question re imported module(s)

2023-05-19 Thread Alan Gauld
On 19/05/2023 19:46, Grizzy Adams wrote:

> Tried that
>  RESTART: D:\Shades\Tools\Python\Temp\cube.py 
 cubes()
> Traceback (most recent call last):
>   File "", line 1, in 
> cubes()
> TypeError: 'list' object is not callable

Ah, now I understand. cubes is a literal list defined in the module.


> But that was spot on, thanks 
> 
 import cube
 cube.cubes
> [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]

Glad to help.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Fwd: Re: sum() vs. loop

2021-10-12 Thread Alan Gauld


On 10/10/2021 09:49, Steve Keller wrote:
> I have found the sum() function to be much slower than to loop over the
> operands myself:
>
> def sum_products(seq1, seq2):
> return sum([a * b for a, b in zip(seq1, seq2)])
>
> def sum_products2(seq1, seq2):
> sum = 0
> for a, b in zip(seq1, seq2):
> sum += a * b
> return sum
>
> In a program I generate about 14 million pairs of sequences of ints each
> of length 15 which need to be summed. The first version with sum() needs
> 44 seconds while the second version runs in 37 seconds.
>
> Can someone explain this difference?

I'm no expert on Python innards but it looks to me like the first
version loops over the length of the list twice, once to generate
the list of products and the second time to add them together.

The pure Python version only loops once because it does the addition
in transit.

Presumably, especially for large numbers, a single python loop
is faster than 2 C loops?

But that's purely my speculation.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Advanced ways to get object information from within python

2021-12-23 Thread Alan Gauld
On 23/12/2021 11:01, Julius Hamilton wrote:
> Lastly, the "help" function.
> 
> I find "help" to similarly be a situation of information overload. 

I assume you know that you can target help() to the specific
attribute or function you need not just the top level classes?

So combined with dir() you can call help on each of the names
that dir() reveals.

That usually produces a much more focused form of documentation.

So in your example:

> dir(scrapy) shows this:

>['Field', 'FormRequest', 'Item', 'Request', 'Selector', 'Spider',
'__all__', '__builtins__', '__cached__', '__doc__', '__file__',
'__loader__', '__name__', '__package__', '__path__', '__spec__',
'__version__', '_txv', 'exceptions', 'http', 'item', 'link',
'linkextractors', 'selector', 'signals', 'spiders', 'twisted_version',
'utils', 'version_info']

> I wish there was a convenient way for me to know what
> all of these are.

help(scrapy.http)
help(scrapy.spiders)
etc...

And if it turns out they are not functions or classes
you can use [p]print to get the values. You can also
use type() to clarify what kind of thing an attribute is.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

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


Fwd: Re: Long running process - how to speed up?

2022-02-19 Thread Alan Gauld
On 19/02/2022 11:28, Shaozhong SHI wrote:

> I have a cvs file of 932956 row 

That's not a lot in modern computing terms.

> and have to have time.sleep in a Python
> script. 

Why? Is it a requirement by your customer? Your manager?
time.sleep() is not usually helpful if you want to do
things quickly.

> It takes a long time to process.

What is a "long time"? minutes? hours? days? weeks?

It should take a million times as long as it takes to
process one row. But you have given no clue what you
are doing in each row.
- reading a database?
- reading from the network? or the internet?
- writing to a database? or the internet?
- performing highly complex math operations?

Or perhaps the processing load is in analyzing the totality
of the data after reading it all? A very different type
of problem. But we just don't know.

All of these factors will affect performance.

> How can I speed up the processing? 

It all depends on the processing.
You could try profiling your code to see where the time is spent.

> Can I do multi-processing?

Of course. But there is no guarantee that will speed things
up if there is a bottleneck on a single resource somewhere.
But it might be possible to divide and conquer and get better
speed. It all depends on what you are doing. We can't tell.

We cannot answer such a vague question with any specific
solution.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

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


Python app on a Mac

2022-04-15 Thread Alan Gauld
I've just migrated from a Linux PC to a Mac mini running Monterey.

I have a Python GUI(Tkinter) app that I wrote on Linux 
and have managed to get working on MacOS except

When I start the program I get a Terminal window as well
as the GUI. On Windows I'd run it with pythonw and in Linux
I just created a desktop launcher to avoid that. But there
is no pythonw on MacOS nor a simple way I can find to
launch apps from the desktop.

Does anyone know how to launch a Python program from the
desktop without a Terminal window (or at least with an
iconified one!) Does it require Applescript or somesuch?

Alan G.

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


Re: Python app on a Mac

2022-04-15 Thread Alan Gauld


On 15/04/2022 19:53, MRAB wrote:

>> When I start the program I get a Terminal window as well
>> as the GUI. On Windows I'd run it with pythonw and in Linux
>> ...
>> Does anyone know how to launch a Python program from the
>> desktop without a Terminal window (or at least with an
>> iconified one!) Does it require Applescript or somesuch?
>>
> There's an answer here:
>
> https://stackoverflow.com/questions/50792048/running-a-python-script-without-opening-terminal

Yes, I've already done all that. The script runs and the GUI
displays but so does a Terminal in the background. The SO answer
does mention you can get the Terminal to close when the
script terminates whhich would be better than now. However,
another answer mentions something called Automator, which
I'll need to Google...

Thanks for the pointer though.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

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


Re: [Tutor] need a tutorial in tokens ,different types

2005-11-20 Thread Alan Gauld
>  could any one suggest me tutorials in different tokenizations and 
> clear describtion of how can i use token type and assign diff attributes 
> to tokens  

What kind of tokens? Are we talking l;exical tokens in a parser 
or security tokens or what?

> also good tutorials in diff data types in python 

The official documentaton explains most of it.

You can try the Raw Materials topic in my tutorial if you like.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: Complementary language?

2005-01-01 Thread Alan Gauld
On Sat, 25 Dec 2004 18:40:31 -0500, HackingYodel
<[EMAIL PROTECTED]> wrote:
> Hello all!  I'm learning to program at home.  I can't imagine a better 
> language than Python for this.  The ideal situation, for me, would be to 
> study two languages at the same time.  Probably sounds crazy, but it 
> works out better for me.  

Me too, thats why my web tutorial features Python, VBSCript and
Javascript. (The previous version had BASIC and Tcl with Python)

> fascinating.  C, D, Objective-C, Ocaml, C++, Lisp, how is a non-tech to 
> choose?  Does any single language do a better job in Python's weaker 
> areas? 

C is better at low level stuff, Prolog is better at declaratie
programming and Haskell is better at functional programming.
Lisp/Scheme are good for giving a good theoretical understanding
(try the SICP and HTDP web sites). And Tcl has a really different
approach which is plain fun to grapple with :-)

I chose VBScript and JavaScript because they have similar
structure to Python (traditional imperative programming 
with OOP) but very different syntax. Plus they were free and
easily available (albeit with VBScript limited to Windows 
users, who are 80+% of my visitors). Javascript is especially
useful since its an easy lead in to learning C/C++, Java, 
even Perl to some extent and a lot of sample code sites 
use those languages.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2005-01-01 Thread Alan Gauld
On Sat, 01 Jan 2005 16:08:07 GMT, [EMAIL PROTECTED] (Cameron
Laird) wrote:

> I argue that it's a false opposition to categorize projects in
> terms of use of single languages.  Many projects are MUCH better
> off with a mix 

In practice I have *never* worked on an industrial scale project
that only used one language. The nearest I came was a small
protocol convertor that only used C, SQL and some shell and 
awk - but that's still 4 languages! And the whole project was
only 40,000 lines of code in about 20 files.

And most projects use many more, I'd guess around 5-8 on an
"average project" of around 300-500kloc. The biggest project I
worked on had about 3.5Mloc and used:

Assembler (680x0 and Sparc),
C
C++
Lisp(Flavors)
awk
Bourne shell
C shell - this was a mistake discovered too late to "fix"
PL/SQL
 - A UI description language for a tool called TeleUse...
Pascal - No, I don't know why...
ASN.1 - with a commercial compiler

We also had some IDL but since it was tool generated I'll ignore
it...

We also had an experimental version running on a NeXt box so it
used Objective C for the UI instead of  and C++...

A total of 13 languages... with 5 geographically dispersed teams
comprising a total of 200 developers (plus about 40 testers).
Interesting times...in the Chinese sense!

Alan G
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What can I do with Python ??

2005-01-01 Thread Alan Gauld
On Sat, 1 Jan 2005 21:57:32 +0100, BOOGIEMAN <
> (let's say C#). Can you make fullscreen game with it (for example) ? 


You can but please don't! Make your game run fast in a window.
I hate fascist games programmers who insist on monopolising a 21
inch 1600x1200 display and assuming I have nothing better to do
than play their game. If that's all I wanted to do I'd stick with
DOS, or buy a Nintendo... I have a multi tasking PC please let me
multi task!


;-)

Alan G.

Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: screen clear question

2005-01-02 Thread Alan Gauld
On Sun, 02 Jan 2005 14:23:07 +0800, Craig Ringer
<[EMAIL PROTECTED]> wrote:
> On Sun, 2005-01-02 at 11:31, jcollins wrote:
> > Is there a command in Python to clear the screen?  That is without writing
> > multiple blank lines.
> 
> Without knowing what 'screen' you're talking about, it's hard to say. If
> you mean clearing a terminal, you can call 'tput clear' or
> '/usr/bin/clear' on many UNIX systems; no idea about Windows.

On Windows the DOS CLS command will clear a command prompt, it
also works for CP/M and VAX terminals too. Finally I think the
curses module allows you to clear a window, including the main
window - ie the terminal screen.

In each case run CLS (or clear) via os.system()

But the bottom line is that there is no builtin command 
because the mechanism is different on each platform.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Frameworks for "Non-Content Oriented Web Apps"

2005-01-02 Thread Alan Gauld
On 1 Jan 2005 20:51:06 -0800, [EMAIL PROTECTED] wrote:
> Is there something that can ease the development of application that
> are not content oriented(I call them "NON CONTENT-ORIENTED WEB
> APPLICATIONS" because I don't know what else to call them). I mean the
> applications like, accounting,  high volume data entry apps,  where
> normally GUI clients have ruled. I know very high quality ERP 



I don;t know of any such frameworks.

The Siebel CRM system may be the kind of thing you mean I think,
but it uses standard technology. IT just puts up a form then uses
client side Javascript to detect changes and send the data
requests to/from the data server... No special frameworks as
such...

HTH,

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: screen clear question

2005-01-02 Thread Alan Gauld
On Mon, 03 Jan 2005 02:15:23 +1000, Nick Coghlan 
> Alan Gauld wrote:
> > But the bottom line is that there is no builtin command 
> > because the mechanism is different on each platform.
> 
> I'd have said it was because the inpreter is line-oriented rather than 
> screen-oriented, but YMMV.

Yeah, that might be a reason as well :-)

But then the early PC GW-Basic or BASICA interpreters were line
based too but both provided a CLS command because the *programs*
that were written were usually screen based... But they ran on a
single OS so a CLS was easily possible.

Alan G.


Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-06 Thread Alan Gauld
On Thu, 30 Dec 2004 23:28:46 +1000, Nick Coghlan
<[EMAIL PROTECTED]> wrote:

> GvR has commented that he want to get rid of the lambda keyword for Python 
> 3.0. 
> Getting rid of lambda seems like a worthy goal, 

Can I ask what the objection to lambda is? 
1) Is it the syntax?
2) Is it the limitation to a single expression?
3) Is it the word itself?

I can sympathise with 1 and 2 but the 3rd seems strange since a
lambda is a well defined name for an anonymous function used in
several programming languages and originating in lambda calculus
in math. Lambda therefore seems like a pefectly good name to
choose.

So why not retain the name lambda but extend or change the syntax
to make it more capable rather than invent a wholly new syntax
for lambdas?

Slightly confused, but since I only have time to read these
groups regularly when I'm at home I have probably missed the bulk
of the discussion over the years.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-07 Thread Alan Gauld
On Thu, 06 Jan 2005 21:02:46 -0600, Doug Holton <[EMAIL PROTECTED]> wrote:
> used, but there are people who do not like "lambda":
> http://lambda-the-ultimate.org/node/view/419#comment-3069
> The word "lambda" is meaningless to most people.  Of course so is "def", 
> which might be why Guido van Robot changed it to "define": 
> http://gvr.sourceforge.net/screen_shots/

The unfamiliar argument doesn't work for me. After all most
people are unfamiliar with complex numbers (or imaginary) numbers
but python still provides a complex number type. Just because the
name is unfamiliar to some doesn't mean we shouldn't use the
term if its the correct one for the concept.

Hopefully anyone who wants to use anonymous functions will know
that such are called lambdas and hopefully will have studied
lambda calculus to at least some level - certainly CS majors and
software engineering types should have...

> Python is easier for beginners to learn than other mainstream 
> programming languages 

Absolutely, but it has to decide (and soon I think) how important
that role is in the development of the language. Many of the more
recent features are beginner hostile - slots, properties, meta
classes, decorators etc... So is Python going to consciously try
to remain beginner friendly (which it remains by simply ignoring
the newer fatures!) or deliberately go for the "fully featured"
general purpose audience?

> Yes, I agree, and either keep the "lambda" keyword or else reuse the 
> "def" keyword for anonymous methods.  See this page Steven Bethard 
> created: http://www.python.org/moin/AlternateLambdaSyntax

I agree, I'm much more concerned about the idea of losing
anonymous functions (aka lambdas) than about losing the name
lambda, its just that the name is so descriptive of what it does!
( In fact it was seeing the name lambda appearing in a Lisp
programme I was reading that got me started in Lambda calculus
many years ago...)

> By the way, you've done great work with your learning to program site 
> and all the help you've given on the python-tutor list:

Aw shucks! Thanks ;-)

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-07 Thread Alan Gauld
On Fri, 07 Jan 2005 08:44:57 -0700, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> > The unfamiliar argument doesn't work for me. After all most
> > people are unfamiliar with complex numbers (or imaginary) numbers
> 
> complex numbers.  Lambdas, on the other hand, show up in all kinds of 
> code, and even though I hardly ever use them myself, I have to 
> understand them because other people do (over-)use them.

That's a fair point I suppose but I still don't see much point in
introducing new names and syntaxes when the existing name is a
sensible one, even if unfamiliar to many. After all it works in
Lisp and Haskell - Haskell even uses Lambda as its emblem...

And besides it may just encoursage some to go and explore Lambda
calculus, it did for me... And my programing improved enormously
as a result. So maybe having the name as a stimulant to research
is a good thing... 

OTOH I do accept the point made by another poster that Pythons
single expression limitations mean that they are a poor imitation
of lambdas in other languages. And provided I get some kind of
anonymous code block to pass around I don't care too much if the
name lambda disappears, provided the concept remains! And the
syntax is reasonably simple to use where lambdas get used now.

(Without lambdas of any kind I might finally make the jump 
to Ruby that I've been toying with for a while but I just hate
those Perl-like @ symbols...)


We often see people stating that programming shouldn't be called
a science because there is no mathematical basis, such claimants
usually haven't seen Predicate or Lambda calculus. I know, I used
to be in that category and while I don't explicitly use either
when programming (or only rarely) awareness of the principles
suddenly made a lot of the "rules of programming" that I'd been
taught make perfect sense (no side-effects, avoid globals, etc)
Its like the fact that I rarely use Maxwell's equations when
designing electronic circuits - but its nice to 
know what the underlying theory is actually based on!


All IMHO of course! :-)

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatic Windows printer creation?

2005-01-23 Thread Alan Gauld
On Wed, 19 Jan 2005 14:35:22 -0500, "GMane Python"
<[EMAIL PROTECTED]> wrote:

> Anyone know if there's a module which will allow me to 'create' windows
> printer definitions?  Not from a Windows domain network, but just to add a
> printer that sends to a jet-direct-attached printer.

The easiest way by far is to use the Windows Script Host objects
from winall. WSH makes creating windows resources like printers
etc fairly easy.

Alan g.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to ncurses on win32 platform

2005-01-24 Thread Alan Gauld
On Mon, 24 Jan 2005 17:06:52 +0100, Brane <[EMAIL PROTECTED]> wrote:
> please advice

You can use ncurses via cygwin.
There are DOS ports too but I couldn't get any of them to 
work on my XP box, YMMV...

Search the Vaults of Parnassus for the DOS Stuff.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice on OSX cocoa app with Python backend

2005-02-02 Thread Alan Gauld
On Tue, 01 Feb 2005 12:12:15 -0500, Socheat Sou
<[EMAIL PROTECTED]> wrote:
> the RDBMS, but some have suggested looking into OODBMS, like PostgreSQL,
> but from what I know of OODBMS they don't seem like the right fit for
> this project.

Calling PostGres an OODBMS might be stretching it a wee bit, but
it does have some OO features certainly. However if you are
simply using the DB as persistence in the server and for
reporting then an RDBMS should be fine and the technology is well
understood.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: noob question

2005-06-27 Thread Alan Gauld
"Matt Hollingsworth" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Very new to python, so a noob question.  When I've written
stuff in
> JavaScript or MEL in the past, I've always adopted the variable
naming
> convention of using a $ as the first character (no, I don't use
perl,

Can I ask why you did that?
Did someone tell you to or did you hit on the idea yourself?
Do you really find it useful? I mean do you often in your
Python coding find a problem with identifying your variables?

I'm curious because one of the things I like most about Python
is the fact I don't need to mess up my programs with spurious
characters like $ etc. And I never have any problem identifying
variables etc in my code. (The same is true of Object Pascal
in Delphi, my other favourite language).

The only place I've ever found Hungarian notation useful was
in C which is a weird mix of static typing and no-typing,
and there the prefix code gives a clue as to what kind of
value you might expect to find. But when I moved to C++ I
dropped the prefixes because they added no value.

In Python Hungarian notation is meaningless since variables
aren't typed anyway.

So I am curious as to why anyone would feel the need to introduce
these kinds of notational features into Python. What is the
problem that you are trying to solve?


-- 
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




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


Re: Life of Python

2005-06-27 Thread Alan Gauld

"Uwe Mayer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> con: If you are planning larger applications (for a reasonable
value of
> "large") you have to discipline yourself to write well
structured code.

As always.

> Then you will want to specify interfaces, accessor functions
with different
> read /write access, ...

Why? What advantage does this really give you over indicative
doc strings? interfaces in particular are a modern madness.
Why not just define a class with a set of unimplemented methods.
Who cares if someone tries to instantiate it? What can they do
with it? They only make sense in languages which are statically
typed and rely on inheritance to implement polymorphism.

Pure accessor methods are usually a mistake anyway, but can
be done using properties if you really must.

> Unless you have designed the software interactions completely
bevorehand
> (which never works out) this is the only way to incorporate
changes without
> refactoring your source all the time.

On really big projects it is fairly normal to define the
structure of the code to quite a detailed level - often
using Case tools and UML etc - so refactoring is only needed
when you discover a hole. Thats true regardless of size of
project but the Case approach tends to limit the damage.

> this should be expanded further, i.e. more build-in decorators
for
> interfaces, abstract classes, parameter and return value
restrictions.

What kind of parameter and return value restrictions?
In a dynamically typed language there is a limit to what can
be applied, and much of that is of limited value IMHO.

> with Perl than with Python and since there is no way of forcing
a
> programmer to do it a certain way,

I'm always uncomfortable about trying to "force" a programmer
to do it a certain way. I can never know what circumstances
those client programmers might be facing when I write/design my
code. And I can never be sure that I know better than the
client programmer.

I've seen too much C++ code that begins

#define private public

to believe that trying to force programmers rather than inform
them is a good idea.

(And FWIW I have worked on several multi million line projects
with upwards of 400 programmers working in 5 or more locatons
in Lisp, C, SQL, COBOL etc. Attempts to impose rules rather
than agreed protocols have never been very helpful in my
experience)

> its often easyer to rewrite Perl programs over 400 lines

That probably has a lot more to do with Perl's inscrutable
syntax and "many ways to do it" approach than any of the
classifiers being discussed here! I certainly didn't find
us rewriting Lisp code rather than enhancing what was there,
and Lisp shares much of Python's approach to life.


-- 
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Ann: New SQL topic in Tutorial

2005-09-19 Thread Alan Gauld
I've added the fist in a series of planned new topics to
my online tutorial. It's on using databases and covers
SQLite and the Python DB API.

Since I'm no expert on either topic (an Oracle and
Interbase user from C++) any feedback is welcomed.

http://www.freenetpages.co.uk/hp/alan.gauld/tutdbms.htm

As in the rest of my tutorial it's aimed at those with
no experience in databases and limited Python experience
(basically the earlier bit of my tutor!). It attempts to
teach enough to make other more complete tutorials
accessible.

Hopefully it will be useful

-- 
Alan G.


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


Re: Python and Unix Commands

2005-09-19 Thread Alan Gauld
>   I have a question relating to how Unix commands can be issued 
> from
> Python programs.

There are numerous methods including the commands module that
you have already discovered, the os.system() call and the
various os.popen/os.execXX calls.

Also Python 2.4 has introduced the subprocess module that
superceded most of these.

> and I need this script to call three other separate Python 
> scripts,
> where each one executes in it own thread of control.

Do you actually need to execute the python scripts as scripts,
each with its own instance of the intrerpreter? (For testing
the answer may well be yes) Or would it be possible to simply
execute the script code as a function from within a thread of
your main program?

commands/os.system/subprocess etc are usually used to launch
Unix commands or other executable files, not other Python
scripts. It's easier to interact with Python from within 
Python...

> use a Unix command to get each script to run in its own shell. 
> I have
> tried using the "Commands" module but after I issue the
> first "command", execution blocks until I kill the called 
> script. Is
> there a way around this??

If you must do this then I'd suggest you need to launch a 
separate
thread per shell then use commands/subprocess to launch each
interpreter/script invocation from within its own thread.

[ If you are not interested in the results you could just use
the Unix '&' character to execute the processes in the
background ]

HTH,


-- 
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld 


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


lambda strangeness??

2005-02-27 Thread Alan Gauld
I was playing with lambdas and list compregensions and came
across this unexpected behaviour:

>>> adds = [lambda y: (y + n) for n in range(10)]
>>> adds[0](0)
9
>>> for n in range(5): print adds[n](42)
...
42
43
44
45
46
>>> adds[0](0)
4

Can anyone explain the different answers I'm getting?
FWIW the behaviour I expected was what seems to happen inside 
the for loop... It seems to somehow be related to the 
last value in the range(), am I somehow picking that up as y?
If so why? Or is that just a coincidence? And why did it work
inside the for loop?

Puzzled,

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda strangeness??

2005-02-27 Thread Alan Gauld
On Sun, 27 Feb 2005 09:07:28 + (UTC), Alan Gauld
<[EMAIL PROTECTED]> wrote:

> >>> adds = [lambda y: (y + n) for n in range(10)]
> >>> adds[0](0)
> 9
> >>> for n in range(5): print adds[n](42)
> ...
> 42
> 43

> the for loop... It seems to somehow be related to the 
> last value in the range(), am I somehow picking that up as y?

Further exploration suggests I'm picking it up as n not y, if
that indeed is what's happening...

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda strangeness??

2005-02-28 Thread Alan Gauld
On Sun, 27 Feb 2005 09:39:49 GMT, Roel Schroeven
<[EMAIL PROTECTED]> wrote:

> adds = [lambda y: (y + n) for n in range(10)]

> You're picking it up not as y but as n, since n in the lambda is
> evaluated when you call the lambde, not when you define it.

> >>> for n in range(10):
>   def f(y, n=n): return y+n
>   adds.append(f)

>>> adds = [lambda x, y=n: (x + y) for n in range(10)]

Works perfectly, thanks Roel.
I knew I'd got this to work in the past with a for loop
so I knew it should be possible in a comprehension. I
just forgot the default argument trick! And then confused myself
by coincidentally using n both inside and outside the LC, thus
apparently getting inconsistent results!

Thanks again,

Alan G.

Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question

2005-02-28 Thread Alan Gauld
On Mon, 28 Feb 2005 16:17:03 +0200, "Ryan White"
<[EMAIL PROTECTED]> wrote:

> How do I display an image in Python? - I've run over Tkinter, but obviously
> in all the wrong places.

Someone else suggested PIL.

But in Tkinter you create a PhotoImage object then insert it into
either a Canvas or a Text widget.

> Any help or sample code would be much appreciated.

If you find the file hmgui.zip on Useless Python you will find
the code for my games framework with an example Hangman game in
Tkinter. It includes the display of a set of images(the hanged
man)

HTH,

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: windows bat file question

2005-03-04 Thread Alan Gauld
On 4 Mar 2005 10:18:08 GMT, Duncan Booth
<[EMAIL PROTECTED]> wrote:
> You will find even more information if you try 'set /?' or 'for /?' at a 
> command prompt. As you say, you can now do quite complicated scripting in 
> command files but it needs masochism second only to Perl programming.

And using WSH is so much easier, even JavaScript and VBScript are
pleasant compared to CMD language... And of course Python can be
used if appropriately installed, but then you'd probably just use
Python!

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: survey

2005-03-04 Thread Alan Gauld
On Fri, 4 Mar 2005 14:14:05 -0800 (PST), Dave Zhu
<[EMAIL PROTECTED]> wrote:

> Is there any survey on scripting languages? I would
> like to get information on several scripting languages
> including Python, Perl, Ruby, Tcl, etc.

There are several such comparisons on the web but most will
naturally reflect the authors personal preferences. The Python
web site has pointers to a couple and I'm sure that Perl , Tcl
and Ruby sites will have their own.

My own personal perspective is that I like Perl for one line
hacks and string processing, I like Tcl because I like the
underlying concepts and Tcl programs are often shorter than
others. I like Ruby mainly for a few of its nice features and I
like Python because I can read it when I'm finished!

Those are the things that influence me, not detailed lists of
features. I like all of the languages you mention and uise them
for different jobs. Vive la difference...

Oh yes, and don't forget to include Lisp/Scheme/Guile in 
your considerations... :-)

Alan G
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: teaching OO

2004-12-06 Thread Alan Gauld
On 24 Nov 2004 18:31:13 GMT, Gabriel Zachmann
<[EMAIL PROTECTED]> wrote:

> You know, I keep wondering exactly what we will be teaching as programming
> languages become easier and easier to learn.
> 
> Programming itself? -- won't be enough for a whole semester.

Oh no way. You could teach a whole semester just using flow chart
stule diagrams. The concepts of programming stay the same
regardless of language. You just won't need to spend so much time
on syntax, you can focus on the real issues like jump tables,
data types - and how the data structure shapes the code
structure! Issues of locking, error handling strategies,
threading, event-handling etc etc... All of these stop being
advanced features and move into mainstream. Someday :-)

> Another question is: can you teach effectively the inner workings, if you
> teach only a dynamic language?

Yes, its just different inner workings. :-)

But to be serious. I've never quite understood the sense in
universities teaching students about how C++ VMTs etc work.
They are only relevant to one language - and possibly one
implementation of one language since they aren't part of the
standard - and languages change on a ~10 yearly cycle. (Which
means Java should soon be making way for the Next Big Thing -
BEPL maybe?...)

Concepts like hashes and jump tables and generic compiler
techniques are universal but how a particular language is
implemented is only of marginal value IMHO. It would be 
like an Electronics professor spending a lecture dismantling 
an oscilloscope and discussing the circuit diagram - mildy
interesting, but ultimately pointless!

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-18 Thread Alan Gauld
On Sat, 18 Dec 2004 08:41:46 +0100, Gregor Horvath
<[EMAIL PROTECTED]> wrote:

> That means that you can set a breakpoint. While the debugger stops you 
> can edit the sourcecode (to some extent) without stopping program 
> execution and let the interpreter run this new code without restarting 
> the program.

You can do that in C/C++ in some environments (within limits).
About 11 years ago I used a C++ IDE called ObjectCenter which
included a C/C++ interpreter and ran on my Sun workstation. It
was pretty cool for the time and worked quite happily on my
350Kloc C program...

If C can do it I'm sure it must be feasible in python!

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-19 Thread Alan Gauld
OK, I'll play...

> > Productive in?

C, C++, Pascal (inc OP/Delphi/Kylix), Python, 
PL/Sql, 80x86 assembler

> > Familiar enough to at least produce code in?

awk, perl, Java, ksh, Lisp, Logo, VBScript, Javascript, Tcl,
DOS batch, SDL

> You forgot an important category here. Can debug, if not produce code
> from scratch:

COBOL, Fortran, BASIC

> > Have toyed with?

Smalltalk, Haskell, Prolog, Snoball, 68xxx assembler, Scheme,
Occam, vim macros, Objective C

> > Want to forget?

COBOL, Occam, Robot, DOS batch, RatFor, vim macros


Alan g
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language fluency (was Re: BASIC vs Python)

2004-12-20 Thread Alan Gauld
On 19 Dec 2004 16:22:03 -0500, [EMAIL PROTECTED] (Aahz) wrote:

> >I'm curious about that last statement. Are you saying that if you
> >write, full time, code for "production", that fluency will decrease? Or
> >that the nifty recent features of Python (generators, etc.) are not
> >useful in "production" code?
> 
> Well, much of my code is maintenance rather than new code, ...
> addition, our base version is currently still 2.2 

Both points are quite common in the wider world of industry.
At work we have Python available on our corporate web site but
its still v 1.5.1 because few people use it and its rarely
updated. On our departmental server we are at 2.2 and the next
uplift will not be till next May at the earliest. Thats when 
the annual tools audit gets done...

Python is not our primary language, in fact its not even on our
preferred tools list, its only tolerated because a few of us have
managed to sneak a few things in. But even our copy of gcc is
version 2.9.5 and C++ is one of our 3 primary languages. A lot of
this has to do with risk avoidance - better the devil you know
and compatibility over lots of different machines.

And finally, whether it be maintenance or new code many
organisations tend to write the same kind of programs. You get to
know the language features you need but not the ones that are out
of your area. (A long time ago I used to write embedded software
in C, it was only when I went on a training course for C++ that I
realized I'd forgotten how to do string handling in C - we only
had LEDs for I/O...! :-)

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-20 Thread Alan Gauld
> >>> was too late).  A machine designed to be run on Forth would have been
> >>> unbelievably powerful from the late 70s to the mid 90s (it would be
> >>> more painful now than the x86 legacy, but still).

A small data point here is that Sun still use Forth in their
Sparc workstations. Their system prompt is really a Forth
interpreter... I don;t know where the interpreter resides,
presumably not in Sparc since its a RISC but interesting that
they still use it. (Or they did last time I used a 
Sparc - 4 years ago?)

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-21 Thread Alan Gauld
On Tue, 21 Dec 2004 16:26:57 GMT, Scott Robinson
<[EMAIL PROTECTED]> wrote:
Speaking of Forth...
> was making the point it would be good for general purpose.  I suspect
> that it would quickly run up against memory limitations and would go
> no faster than the machine driving the memory market (with a possible
> last gasp when Rambus came online).

I dunno. Here in the UK there was a small home computer called (I
think) the Oric(*) which had a membrane keyboard, 4K or RAM and
ran Forth.It had a small cult following before dying out. It
looked a bit like the early Sinclair/Timex ZX81 and I think the
developers came from that stable.

(*)I suspect the name was a dedication to a populat SciFi series
of the time, Blake's 7, which had a computer called Orac...

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda going out of fashion

2004-12-23 Thread Alan Gauld
On Thu, 23 Dec 2004 14:13:28 +1000, Stephen Thorne
<[EMAIL PROTECTED]> wrote:
> I'm a little worried about the expected disappearance of lambda in
> python3000. I've had my brain badly broken by functional programming
> in the past, and I would hate to see things suddenly become harder
> than they need to be.

Me too.
But its not only about becoming harder, I actually like the fact
that lamda exists as a tie in to the actual concept of an
anonymous function. When you read a math book on lambda calculus
its nice to transform those concepts directly to the language.

The current Pythonic lambda has its limitations, but being able
to explicitly create lambdas is a nice feature IMHO. Its much
better than having to create lots of one-off single use functions
with meaningless names.

It can't be that hard to maintain the lambda code, why not just
leave it there for the minority of us who like the concept?

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda going out of fashion

2004-12-23 Thread Alan Gauld
On 22 Dec 2004 23:21:37 -0800, [EMAIL PROTECTED] wrote:

> but if lambda keyword is removed, I swear I will not use the python
> anymore.

While I would be dissappointed to lose lambda, I think losing
Python would hurt me a lot more! After all we aren't losing
functionality here, just adding sonme extra work and losing some
readability. Pythonic lambdas are just syntactic sugar in
practice, they just make the code look more like true 
functional code.

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-24 Thread Alan Gauld
On Fri, 24 Dec 2004 12:30:15 +, Alan Kennedy
<[EMAIL PROTECTED]> wrote:

> [Alan Gauld]
>  > I dunno. Here in the UK there was a small home computer called (I
>  > think) the Oric(*) 
> I'm afraid your memory fails you ...
> 
> The Oric-1 had a keyboard with *actual* keys, and came in two memory 
> 
> I think you're mixing up the Oric with the Jupiter Ace 

Seems to be, I plead old age :-)

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Alan Gauld
On 30 Dec 2004 08:58:36 -0800, "Sridhar  R"
<[EMAIL PROTECTED]> wrote:
> What makes such companies to choose Java over dynamic, productive
> languages like Python?  Are there any viable, technical reasons for
> that?

Decisions are made by men in suits who read very expensive
business magazines, read "technical reports" by the like of
Gartner and Forester and get taken on expenses-paid trips by
company sales reps. My boss has never had his lunch paid 
for by a man selling Python...

Think about the PHB in Dilbert, if some guy in a sharp suit from
a big supplier says use Java, while Dilbert and the others say
Python what will he pick?

There are some valid technical reasons to do with performance and
security too, but frankly, they come a long way down the list...

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which book to read next??

2014-04-21 Thread Alan Gauld

On 21/04/14 15:13, lee wrote:

Hi, I have read the book 'a byte of python' and now I want to read
another book. But I just get confused about which one to read next.
There is a book list below:
1, pro python
2, python algorithms
3, python cookbook
4, the python standard library by examples
which one is suitable for me??


We would need to know a lot more about you.
What is your skill level in programming (as opposed to python)?
What are your areas of interest?
What is your preferred teaching style? In depth background
detail or surface level but hands-on style?

Book choice is always a very personal thing.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

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


Re: Question About Image Processing in Python

2015-05-28 Thread Alan Gauld

On 28/05/15 11:34, Serge Christian Ibala wrote:


I want to know which version of Python is compatible (or can be
associated with which version of which "tools or package" for image
processing)


It would help if you told us what kind of image processing.
If you mean programmatic manipulation of images similar
to what would be done using GIMP/Photoshop then the most
common tools are ImageMagick and Pillow. But you mention
neither, so I'm guessing you are looking at doing
something else - maybe trying to analyze content?

Given the list of tools you list I'd suggest fetching
an all-in-one distro like Anaconda or Canopy. That
way somebody else does the dependency dance for you.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: try/exception - error block

2014-08-03 Thread Alan Gauld

On 03/08/14 18:52, bruce wrote:


but in all that.. no one could tell me .. why i'm not getting any
errs/exceptions in the err file which gets created on the exception!!!


Does the file actually get created?
Do you see the print statement output - are they what you expect?

Did you try the things Steven suggested.


   except Exception, e:
 print e
 print "pycolFac1 - error!! \n";
 name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE)
 name=name.communicate()[0].strip()
 name=name.replace("-","_")


This is usually a bad idea. You are using name for the process and its 
output. Use more names...

What about:

uuid=subprocess.Popen('uuidgen -t',shell=True,stdout=subprocess.PIPE)
output=uuid.communicate()[0].strip()
name=output.replace("-","_")


 name2="/home/ihubuser/parseErrTest/pp_"+name+".dat"


This would be a good place to insert a print

print name2


 ofile1=open(name2,"w+")


Why are you using w+ mode? You are only writing.
Keep life as simple as possible.


 ofile1.write(e)


e is quite likely to be empty


 ofile1.write(aaa)


Are you sure aaa exists at this point? Remember you are catching all 
errors so if an error happens prior to aaa being created this will

fail.


 ofile1.close()


You used the with form earlier, why not here too.
It's considered better style...

Some final comments.
1) You call sys.exit() several times inside
the try block. sys.exit will not be caught by your except block,
is that what you expect?.

2) The combination of confusing naming of variables,
reuse of names and poor code layout and excessive commented
code makes it very difficult to read your code.
That makes it hard to figure out what might be going on.
- Use sensible variable names not a,aaa,z, etc
- use 3 or 4 level indentation not 2
- use a version control system (RCS,CVS, SVN,...) instead
  of commenting out big blocks
- use consistent code style
 eg with f as ... or open(f)/close(f) but not both
- use the os module (and friends) instead of subprocess if possible

3) Have you tried deleting all the files in the
/home/ihubuser/parseErrTest/ folder and starting again,
just to be sure that your current code is actually
producing the empty files?

4) You use tmpParseDir in a couple of places but I don't
see it being set anywhere?


That's about the best I can offer based on the
information available.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

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


Re: [Tutor] Convert Qstring to string in windows

2014-10-16 Thread Alan Gauld

On 16/10/14 19:14, Danny Yoo wrote:


need more information.  But I think you may get better help on a
Qt-specific mailing list; I suspect very few of us here have Qt
experience.


There are at least 2 Python Qt mailing lists and also two for
Side which is Nokia's public domain fork of Qt. That's probably
worth a look too.

Definitely in the minority interest camp on the tutor list.

hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

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


Re: What is the difference between "new Class()" and "Class()"?

2011-11-20 Thread Alan Gauld

On 20/11/11 21:16, Herman wrote:

What is so special about the "new" operator?


Assuming you mean the __new__() method?

__new__() gets called when the class is being constructed, it returns 
the new instance. It is the real Pyhon constructor.


As opposed to __init__() which is called after the instance has been 
created. It is not really a constructor but an initializer. (Even though 
most of us treat it as a constructor!)


But you should never see code like

meat = new Spam().

it should be

meat = Spam()

Which calls __new__() followed by __init__().

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: Top Programming Languages of 2013

2007-10-07 Thread Alan Gauld

"Dick Moores" <[EMAIL PROTECTED]> wrote 

> 
> 

Interesting, but I'm not sure what the criteria for "top" is.
Is it a measure of power, popularity, usage?

Scary that HTML/CSS should be so high though 
given its not a programming language at all!

Alan G.

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


Re: Traversing python datatypes via http

2008-02-05 Thread Alan Gauld
"Mark" <[EMAIL PROTECTED]> wrote

> Is it possible to traverse say python lists via http://

http is a network protocol.
What does that have to do with traversing python lists?
Can you clarify what you mean by that?

> say there is a list in the memory
> can we traverse the list using list/next list/prev list/first 
> list/last

Not with a standard list although its not hard to do by defining
your own class wrappibng a list.

You can however traverse a list using a standard for loop:

for item in [1,2,3,4,5]:
print item

And you can use range() to generate a set of indices
that will allow you to iterate by more unusual step sizes
And you can use normal indexing to go to the first element(0)
or the last element(-1)

I'm not sure if that answers your question.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] Having Issues with CMD and the 'python' command

2008-12-15 Thread Alan Gauld

"bob gailer"  wrote


Try this:

Start->Settings->Control Panel->System->Advanced->Environment 
Variables

Highlight PATH under System Variables & Click Edit.
Add ;C:\python26


And notice that Bob said ADD - DO NOT REPLACE the existing setting or
you will likely break stuff and its not easy to fix it afterwards 
unless

you have a full backup to hand!!

Alan G. 



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


Re: Help with my program

2009-10-23 Thread Alan Gauld


"tanner barnes"  wrote

I have a program with 2 classes and in one 4 variables 
are created (their name, height, weight, and grade). 
What im trying to make happen is to get the variables 
from the first class and use them in the second class.


In general thats not a good idea. Each class should 
manage its own data and you should pass objects 
between objects. So first check that whatever your 
second class wants to do with the data from your first 
class can't be done by the first class itself via a method.


If you really do need to access the data there are 
several approaches:


1) Direct access via the object

class C:
  def __init__(s):
  s.x = 42

class D:
   def f(s, c):
  s.y = c.x# direct access to a C instance

2) Access via a getter method returning each variable:

class C:
  def __init__(s):
  s.x = 42
  def getX(s):
  return s.x

class D:
   def f(s, c):
  s.y = c.getX()# access via a getter method

3) Access via a logical operation that returns all public data

class C:
  def __init__(s):
  s.x = 42
  s.y = 66
  def getData(s):
  return (s.x, s.y)

class D:
   def f(s, c):
  s.x, s.y = c.getData()# access via a logical access method

My personal preference in Python is (1) for occasional single 
value access (akin to a friend function in C++) or (3) for more 
regular access requests.


But most of all I try to avoid cross class data access wherever possible. 
As Peter Coad put it "Objects should do it to themselves"

Otherwise known as the Law of Demeter.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: Python-os. Command Execution

2011-02-19 Thread ALAN GAULD


> when user click install, It will start one GUI  installation script and
> exit my application
> 
> This my task.. The problem  was the installation script started but
> control will be transfered  to
> 
> other window ... when installation finished the GUI application will  be 
>closed..
> 
> code:
> 
> os.system("ls -l") &  root.destroy
> 

First question is, why are you using the bitwise and operator to manage 
execution status. This is Python not C. Use clear logic that erflects 
what you are trying to do.( Especially if you only post code fragments.)

if os.system('ls -l') != 0 : root.destroy()

Is much more obvious in intent.

> when execute a command "ls -l " and application will be  closed

Only if os.system returns an error code

> os.system("top") & root.destroy
> 
> Control will  the transferred to the other-window, "top" closed means
> application will be  closed.. plz..help me..

I have no idea what other window you are referring to. Is it the 
OS console that top runs in? Have you checked the return code 
of os.system to see if it returns cleanly (ie a 0) or if it returns an error?

You might find it better to use the subprocess module instead of 
os.system. There is more flexibilityy and control available there.

> I checked also the command as background  process.. like os.system("top
> &") & root.destroy

And what happened?

We need a bit more context and you need to do a bity more debugging.
Starting with getting rid of the bitwise and "trick" from C. All it does 
here is make it hard to understand whats happening.

HTH,

Alan G.
Author of the Learn to Program web site
http://www.alan-g.me.uk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Arguments from the command line

2010-09-06 Thread Alan Gauld


"aug dawg"  wrote

Mercurial is written in Python. I know that commit is a function 
that
commits to a repo, but what command does the program use in order to 
get the
commit name, like "This is a commit name" (This would make a commit 
with

"This is a commit name" as the commit name)


Take a look at the Talking to the User topic in my tutorial which has
a section on reading command line arguments.

Interestingly, most of the queries I get on that section are from GUI 
users

who don't understand the concept of command line arguments! :-)


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: Commercial or Famous Applicattions.?

2010-11-08 Thread Alan Gauld


"Jorge Biquez"  wrote

Can you mention applications/systems/solutions made with Python that 
are well known and used by public in general? ANd that maybe we do 
not know they are done with Python?


The Python web site has an advocacy section, you will find several
success stories  there.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



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


Fwd: Re: AUTO EDITOR DIDN'T WORK

2023-06-12 Thread Alan Gauld via Python-list


On 12/06/2023 10:26, Real Live FootBall Tv via Python-list wrote:

> I did it because I was going to use it with another application, A VIDEO
> EDITING APP, Auto EDITOR but it didn't work for some reasons unknown to me.

You need to define "didn't work"
Did it work as a python interpreter?
ie. Did you get a >>> prompt in a terminal?
and without involvement from your video editor?
If so, what did you do to link it to the video editor?
And what was the result?

Or did Python not even start? How did you try to use it?
What OS are you on? Did the installer run OK?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



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


Fwd: AUTO EDITOR DIDN'T WORK

2023-06-13 Thread Alan Gauld via Python-list
Forwarding to list

Okay thanks. Meanwhile, I am not tech savvy so I may not say much here.
I followed all the commands as given on the website to install auto
editor standing it on python but after rendering the XML file, I
couldn't open it with my Davinci Resolve 18. I uninstalled and
reinstalled about twice and still no success hence I uninstalled it.

On Mon, 12 Jun 2023, 23:33 Alan Gauld via Python-list,
mailto:python-list@python.org>> wrote:


On 12/06/2023 10:26, Real Live FootBall Tv via Python-list wrote:

> I did it because I was going to use it with another application, A
VIDEO
> EDITING APP, Auto EDITOR but it didn't work for some reasons
unknown to me.

You need to define "didn't work"
Did it work as a python interpreter?
ie. Did you get a >>> prompt in a terminal?
and without involvement from your video editor?
If so, what did you do to link it to the video editor?
And what was the result?

Or did Python not even start? How did you try to use it?
What OS are you on? Did the installer run OK?


-- Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/ <http://www.alan-g.me.uk/>
http://www.amazon.com/author/alan_gauld
<http://www.amazon.com/author/alan_gauld>
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
<http://www.flickr.com/photos/alangauldphotos>



-- https://mail.python.org/mailman/listinfo/python-list
<https://mail.python.org/mailman/listinfo/python-list>

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


Re: Fwd: AUTO EDITOR DIDN'T WORK

2023-06-15 Thread Alan Gauld via Python-list
On 15/06/2023 08:58, Real Live FootBall Tv via Python-list wrote:
> I have followed the instructions given on how to install the app. What I
> needed was an application to cut of silence from my video and I saw auto
> editor demonstrated as one of the applications that could do that. It does
> cut the silent areas of an MP4 format video for instance but would save it
> as a XML file which in turn would be exported to the video editor that
> supports the output from the auto editor app. The one who demonstrated it
> in a video used Davinci Resolve to import the XML file, I followed same
> process but I couldn't get same result.

It looks like you have three parts to this puzzle:
- auto-editor
- resolve
- Python

It's not clear which part isn't working but you can at
least test Python is working after you install it
by running the interpreter in a console/terminal
window by typing python at the command prompt.

If you get the Python prompt:

>>>

Then Python is installed OK.

After that it's back into auto-editor and resolve and this is
not the best place to get answers for those. Resolve at least
has an active support forum, so I'd start there(assuming
python works!)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Alan Gauld via Python-list
On 03/07/2023 19:39, Chris Angelico via Python-list wrote:
> On Tue, 4 Jul 2023 at 03:39, Peter Slížik via Python-list
>> The legacy code I'm working with uses a classic diamond inheritance. 

> What happens when Top is initialized twice? This seems like a problem
> waiting to happen, and when you moved to using super(), you more than
> likely simplified things and fixed things.

Slightly off topic but I wonder how many real world problems
people have experienced having the top of a diamond initialized
twice? The reason I ask is that I ran a maintenance team for
about 5 years (early 1990s) working on various OOP projects using MI;
in Lisp Flavors, C++(*) and a homebrew variant of C that supported MI.
In that time I don't recall ever having problems with top objects
being initialized twice (apart from redundant execution of code
of course).

In most cases the top object was so abstract that its init()/constructor
was only doing generic type stuff or opening database sessions/networks
etc which got lost and tidied up by garbage collectors.

So I'm curious about how big this "big problem with MI" is in
practice. I'm sure there are scenarios where it has bitten folks
but it never (or very rarely) occurred in our projects. (Of
course, being maintenance programmers, the problems may have
been ironed out before the code ever reached us! But that
wasn't usually the case...)

(*) C++ is the odd one out because it doesn't have GC, but then
neither does it have an Object superclass so very often MI in C++
does not involve creating diamonds! And especially if the MI
style is mixin based.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Multiple inheritance and a broken super() chain

2023-07-05 Thread Alan Gauld via Python-list
On 05/07/2023 01:27, Chris Angelico via Python-list wrote:

>> So I'm curious about how big this "big problem with MI" is in
> 
> Who said it's a big problem with MI? 

I think it's a very common perception, particularly with
newer programmers who have never used it in anger. Any
time anyone discusses MI it seems somebody will jump in
and warn about diamonds etc. As a result many steer clear
of MI, which is a shame.

My personal experience of MI is that used appropriately
it is a powerful and useful tool. But it must be used
in a true is-a type relationship and not just as a kind
of cheap reuse mechanism - that's when problems start.

Also, mixin style MI is particularly powerful but the
protocol between mixin and "subclass" needs to be carefully
designed and documented. Like any powerful tool you need
to understand the costs of use as well as the potential
benefits.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Why do I always get an exception raised in this __init__()?

2023-09-01 Thread Alan Gauld via Python-list
On 31/08/2023 22:15, Chris Green via Python-list wrote:

> class Gpiopin:
> 
> def __init__(self, pin):
> # 
> #  
> # scan through the GPIO chips to find the line/pin we want 
> # 
> for c in ['gpiochip0', 'gpiochip1', 'gpiochip2', 'gpiochip3']:
>  
> chip = gpiod.Chip(c)
> for l in range(32):
> line = chip.get_line(l)
> if pin in line.name():
> print("Found: ", line.name())
> return
> else:
> raise ValueError("Can't find pin '" + pin + "'")

You don't store the line anywhere.
You need to use self.line
self.line = chip.get_line(l)
if pin...

> def print_name(self): 
> print (self.line.name()) 
>  
> def set(self): 
> self.line.set_value(1) 
>
> def clear(self): 
> self.line.set_value(0) 

As you do here.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Why doc call `__init__` as a method rather than function?

2023-09-15 Thread Alan Gauld via Python-list
On 15/09/2023 11:49, scruel tao via Python-list wrote:
> ```python
 class A:
> ...   def __init__(self):
> ... pass

> On many books and even the official documents, it seems that 
> many authors prefer to call `__init__` as a "method" rather 
> than a "function".

That' because in OOP terminology methods are traditionally
implemented as functions defined inside a class (There are
other ways to define methods in other languages, but the
class/function duology is by far the most common.)

What is a method? It is the way that an object handles a
message. OOP is all about objects sending messages to each
other. Many different objects can receive the same message
but they each have their own method of handling that message.
(This is called polymorphism.)

Over time the most common way to implememt OOP in a language
is to invent a "class" structure and to allow functions to
either be defined within it or added to it later. In either
case these functions are what define how a class (and its
object instances) handle a given message. So the function
describes the method for that message. And over time that
has become shortened to the function inside a class *is*
its method.

In practice, the message looks like a function call. And
the method consists of the function body (and/or any
inherited function body). Thus every method is a function
(or set of functions) but not every function is a  method
(or part of one).

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Question(s)

2023-10-24 Thread Alan Gauld via Python-list
On 24/10/2023 22:51, Grant Edwards via Python-list wrote:

>>> Is there a way to verify that a program is going to do what it is
>>> supposed to do even before all the hardware has been assembled and
>>> installed and tested?
> And the specified customer requirements are usually wrong too. Sure,
> the customer said it is supposed to do X, but what they actually
> needed was Y.

And this is the hardest bit, specifying exactly what you want at
a level that can be formally verified. I worked on some safety
critical systems a while back(1990s) and we had to formally verify
the core (non UI) code. We did this, but it still failed in some
scenarios because we verified it against faulty specs which,
in turn, were based on the customer's incorrectly stated requirements.
Garbage-In-Garbage-Out still applies.

Was the 3 months of formal analysis a waste of time? No, we still
caught lots of subtle stuff that might have been missed, but it
wasn't 100%. The bugs we did have were caught and identified
during system tests. So far as I know, nobody has died as a
result of any bugs in that system.

But, to the OP, the effort in
a) Learning the math and gaining experience for formal analysis and
b) actually performing such an analysis of real design/code
is simply not worth the effort for 99% of the programs you will write.
It is much simpler and faster to just test. And test again. And again.
Especially if you use automated testing tools which is the norm nowadays.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Question(s)

2023-10-24 Thread Alan Gauld via Python-list
On 25/10/2023 00:08, o1bigtenor via Python-list wrote:

> So how does one test software then?

Testing is very different to proving!
As an industry we do a lot of testing at many different levels.
On bigger projects you'll find:
- Unit tests - testing small fragments of a bigger program
- Integration tests - testing that sub modules of code work
  together (and code with hardware, if applicable)
- System testing - checking that the code(and hardware) as a
  whole does what it should based on the specs (often done
  by an independent team)
- Performance testing - checking the system runs as fast as it
  should, using only the memory it should, for as long as it should.
- User testing - Can a real user drive it?
- security testing - Does it stop the bad guys from messing it
  up or using it as a gateway?

And there are more levels if you are really keen.
Testing often(usually!) takes up more time than programming.
And there are many, many books written about how to do it.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Question(s)

2023-10-25 Thread Alan Gauld via Python-list
On 25/10/2023 12:44, o1bigtenor via Python-list wrote:

> Haven't heard of a python IDE - - - doesn't mean that there isn't such - -

There are literally dozens with varying degrees of smartness.
The big 4 all have Python plugins/environments:
Eclipse, Netbeans, VisualStudio, IntelliJ

And of course the Apple XCode toolset has a python environment.

There are also several Python specific IDEs around too.
Most of them are multi-platform:

https://www.simplilearn.com/tutorials/python-tutorial/python-ide

gives a small sample

And of course the old favourites vi/vim and emacs both have
comprehensive Python support.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: xor operator

2023-11-13 Thread Alan Gauld via Python-list
On 14/11/2023 00:33, Mats Wichmann via Python-list wrote:
> Hardware and software people may have somewhat different views of xor

I've come at it from both sides. I started life as a telecomms
technician and we learned about xor in the context of switching
and relays and xor was a wiring configuration for scenarios where
you wanted any single change of switch state to toggle the
entire system (think a stairwell with switches on every
landing).

Later, I got into software engineering and we studied Boolean
algebra and xor was an odd number of Truth values, used in
parity tests (and in encryption).

But from both perspectives xor is pretty clearly defined
in how it operates and not, I suspect, what the OP really
wants in this case.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: Newline (NuBe Question)

2023-11-15 Thread Alan Gauld via Python-list
On 15/11/2023 07:25, Grizzy Adams via Python-list wrote:

> for s in students:
> grades.append(s.school)
> grades.append(s.name)
> grades.append(s.finalGrade())
> if s.finalGrade()>82:
> grades.append("Pass")
> else:
> grades.append("Fail")
> print(grades)
> 
> --- End Code Snippit  ---

> Do I need to replace "append" with "print", or is there a way to get the 
> newline in as I append to list?

Firstly, it is usually a bad idea to mix formatting features(like
newline) with the data. You will need to remove them again if you want
to work with the data itself.

So, better to print the raw data and add the formatting during printing.

There are a couple of options here (well more than a couple actually!)
The simplest is to create another for loop and print each field with a
newline automatically added by print()

Another is to simply join everything in grades together separated by
newlines. Python has a method to do that called join():

print('\n'.join(grades))

Unfortunately it seems your data has a mix of strings and numbers so
that won't work without some tweaks:

print('\n'.join(str(f) for f in grades))


However, I wonder if this really what you want? You have created grades
as a long list containing all of the attributes of all of the students
plus their Pass/Fail status. But you have no (easy)way to access the
Pass/Fail value for each student. Do you really want to store the
Pass/Fail in the student? And then print the students? Like so:

for s in students
if s.finalGrade() > 82:
   s.result = "Pass"
else:
   s.result = "Fail"
print(s.school)
print(s.name)
...
print(s.result)

Just a thought...

PS. There are neater ways to do this but you may not have covered
those yet so I'll stick to basics.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Amy known issues with tkinter /ttk on latest MacOS?

2023-11-16 Thread Alan Gauld via Python-list
I have a little app that I wrote ages ago (2015) using tkinter/ttk
and it just works. Or it did, up until the latest MacOS version upgrade
and now it has become very sporadic in response to mouse clicks.

For example I have a drop-down list and I can drop the list but
then it won't let me select an item. Or sometimes, the selected
item is highlighted but the corresponding action doesn't get fired.
It is intermittent which makes debugging it difficult. And it's
not just lists it also affects regular buttons as well.
Right clicks seem to work ok, it's only the left mouse button.
Also, I've just noticed that if I move the mouse slightly while
clicking that seems to work. There are no error/warning
messages in the Console.

I'm just wondered if this is a known issue, or just my setup?
Any suggestions welcomed.

Python version - 3.10.4
OS version - Sonoma 14.1
M1 Mac Mini, 16GB Ram

I could upgrade my Python version but I was planning on waiting
for the 3.13 release to finalize first. And I doubt if that's
the cause anyway.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

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


Re: Amy known issues with tkinter /ttk on latest MacOS?

2023-11-19 Thread Alan Gauld via Python-list



On 17/11/2023 03:38, Terry Reedy wrote:
> There have been other reports on the cpython issue tracker than Sonoma 
> broke bits of tk behavior.
> https://github.com/python/cpython/issues?q=is%3Aissue+label%3AOS-mac+is%3Aclosed
>  
> shows a couple

Thanks Terry, I had a browse and it seems I'm not alone. That's a relief.

I'll upgrade to 3.13 when it comes out and hopefully it will go
away. (Another suggestion was to use the homebrew python but I don't
like having any more homebrew stuff than is absolutely necessary!)

Meantime I'll just have to continue nudging the mouse as I click!

Alan G.


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


Exploring terminfo

2021-01-14 Thread Alan Gauld via Python-list
During lockdown I've been digging deeper into the curses module
and lately into the ti family of functions that reside there.

I've written a short program that is supposed to
- *clear the screen*,
- read some input
- display the result in a message *highlighted in bold*.
- get input to end the program

The parts marked with ** use terminfo, or they should.
My problem is that while the clear-screen part works the
bold bit only appears in the final input(), not in the
output message.

Here is the code:

#
import curses as cur
cur.setupterm()

bold = cur.tigetstr('bold')
cls = cur.tigetstr('clear')

cur.putp(cls)
name = input("Hello, what's your name? ")

cur.putp(bold)
print("Nice to meet you ", name)

input("\nHit enter to exit")
###

I've tried variations on flush both inside and outside
the print() - both before and after.
I've tried writing to stdout instead of print, but nothing is working.
The Hit enter... message is in bold but the Hello... line isn't.

Does anyone know what's going on and how to fix it.

I could, of course, jump into full curses but I wanted to
see if I could use the terminfo stuff directly to retain
use of regular input() and print() functions.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


  1   2   3   >