[Tutor] smtplib help required

2010-04-23 Thread James Chapman
Hi there gurus and everyone else. This is my first post to this group, and I'm turning here because I'm stumped and search engines are not helping. I've used smtplib for a few things already and while wanting to use it again today, I'm having weird things happen. Basically, my code looks like thi

Re: [Tutor] smtplib help required

2010-04-23 Thread James Chapman
D'Oh! Of course!  I feel like a right pillock now. Cheers for that though. -- James At Saturday, 24-04-2010 on 0:39 Jerry Hill wrote: On Fri, Apr 23, 2010 at 6:41 PM, James Chapman wrote: > Hi there gurus and everyone else. This is my first post to this group, and > I'm turn

Re: [Tutor] python telnet

2011-11-19 Thread James Chapman
traceback has: child = winspawn('telnet 192.168.0.55:210') When using telnet from CLI (on windows), you would type: telnet 192.168.0.55 210 Note the space between the IP and port number and not a :colon. Not sure this is your problem but probably worth mentioning. -- James At Saturday, 19/11

[Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
Hi there python list. I'm trying to open a text file named "This is_a-test'FILE to Ensure$ that£ stuff^ works.txt" (without the quotes) but I'm struggling to find a way to open it. >>> filename = "This is_a-test'FILE to Ensure$ that£ stuff^ works.txt.js" >>> open(filename) Traceback (most recent

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
Thanks Tim, while this works, I need the name to be stored in a variable as it's dynamic. In other words, how do I rewrite open(u"blah£.txt") to be filename = "blah£.txt" open(filename) At Thursday, 28/06/2012 on 18:39 Tim Golden wrote: On 28/06/2012 18:19, James

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
rror: 'utf8' codec can't decode byte 0x9c in position 35: invalid start byte -- James At Thursday, 28/06/2012 on 18:58 Jerry Hill wrote: On Thu, Jun 28, 2012 at 1:55 PM, James Chapman wrote: > Thanks Tim, while this works, I need the name to be stored in a variable as > it&#x

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
Informative thanks Jerry, however I'm not out of the woods yet. > Here's a couple of questions that you'll need to answer 'Yes' to > before you're going to get this to work reliably: > > Are you familiar with the differences between byte strings and unicode > strings? I think so, although I'm

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
8/06/2012 on 21:17 Tim Golden wrote: On 28/06/2012 20:48, James Chapman wrote: > The name of the file I'm trying to open comes from a UTF-16 encoded > text file, I'm then using regex to extract the string (filename) I > need to open. OK. Let's focus on that. For the moment

Re: [Tutor] reading an input stream

2016-01-07 Thread James Chapman
Hi Richard There are a number of considerations you need to take into account here. Raw sockets is almost never the right solution, while a basic socket to socket connection is easy enough to program, handling failure and concurrency can very quickly make the solution a lot more complex than it n

Re: [Tutor] Question about the memory manager

2016-01-11 Thread James Chapman
If you read the comment that goes with the code snippet pasted in the original email it makes far more sense as the author is talking specifically about out of memory errors... "You already got excellent answers, I just wanted to add one more tip that's served me well over the years in a variety

Re: [Tutor] Modularity

2016-01-14 Thread James Chapman
May I suggest: https://docs.python.org/2/tutorial/modules.html In particular: * https://docs.python.org/2/tutorial/modules.html#the-module-search-path * https://docs.python.org/2/tutorial/modules.html#packages Now the next bit of advice is likely to be controversial but I have good reasons for i

Re: [Tutor] Procedure to install dlib on windows?

2016-01-14 Thread James Chapman
>From one of the Python examples: # COMPILING/INSTALLING THE DLIB PYTHON INTERFACE # You can install dlib using the command: # pip install dlib # # Alternatively, if you want to compile dlib yourself then go into the dlib # root folder and run: # python setup.py install # or #

Re: [Tutor] Modularity

2016-01-14 Thread James Chapman
I should have re-read that last reply before hitting send. Apologies for the poor sentence construction! Something I forgot to highlight before which might be related to your initial question. If you have a file called sound.py which contained a class called WavFile, if you imported just sound li

[Tutor] Mocking with "mock" in unit testing

2014-01-16 Thread James Chapman
Hi all I have a question regarding mocking in unit testing. Let's assume I have the following class: --- import subprocess class Pinger(object): def ping_host(self, host_to_ping): cmd_string = 'ping %s' % (host_to_ping) cmd_args = cmd

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-17 Thread James Chapman
pinger = pinger.Pinger() with mock.patch('pinger.subprocess') as subprocess: subprocess.Popen.return_value.returncode = 1 self.assertRaises(Exception, pinger.ping_host, 'localhost') if __name__ == '__main__': unittest.main() --------

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-17 Thread James Chapman
__name__ == '__main__': unittest.main() - -- James On 17 January 2014 10:50, eryksun wrote: > On Fri, Jan 17, 2014 at 4:58 AM, James Chapman > wrote: > > import mock > > import unittest > > import pinger > > > > class T

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-17 Thread James Chapman
rrors. -- James On 17 January 2014 11:23, Steven D'Aprano wrote: > On Fri, Jan 17, 2014 at 09:58:06AM +, James Chapman wrote: > > > As this question was just about mock and not really dealing with the bad > > return code or exception handling or raising my final working e

Re: [Tutor] Mocking with "mock" in unit testing

2014-01-17 Thread James Chapman
On 17 January 2014 15:32, Steven D'Aprano wrote: > > On Fri, Jan 17, 2014 at 08:35:04AM -0500, eryksun wrote: > > On Fri, Jan 17, 2014 at 6:23 AM, Steven D'Aprano > > wrote: > > > On Fri, Jan 17, 2014 at 09:58:06AM +, James Chapman wrote: > [...] > &

[Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
Hello tutors I've constructed an example which shows a problem I'm having testing a real world program and would like to run it past you. tutor_question.py -- # -*- coding: utf-8 -*- import sys import threading import time class Time_Printer(threading.Thread)

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
alls were made. ** Obviously the print lines will be substituted for some kind of assert lines ** FYI I'm using CPython 2.7. -- James On 31 January 2014 12:57, eryksun wrote: > > On Fri, Jan 31, 2014 at 6:31 AM, James Chapman wrote: > > try: > > while se

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
James On 31 January 2014 13:21, Steven D'Aprano wrote: > On Fri, Jan 31, 2014 at 11:31:49AM +, James Chapman wrote: >> Hello tutors >> >> I've constructed an example which shows a problem I'm having testing a real >> world program and would like to

[Tutor] When to use multiprocessing Managers?

2014-02-25 Thread James Chapman
Hello tutors I'm curious about managers and when to use them. For example, I see they offer a Queue() for sharing a Q between processes, but if I create a Q in the parent process and pass it down to child processes, then they can put messages into that Q just fine, and I presume the same thing for

Re: [Tutor] When to use multiprocessing Managers?

2014-02-28 Thread James Chapman
mportant if I was writing to a Queue and expecting all threads to see that message? Although if I needed to command a thread to do something I'd probably have a separate class and separate thread for that purpose. James -- James On 26 February 2014 14:19, David Palao wrote: > 2014

Re: [Tutor] Python help

2014-02-28 Thread James Chapman
The answer lies in this page: http://docs.python.org/3.3/library/stdtypes.html#string-methods -- James On 28 February 2014 11:44, James Chapman wrote: > The answer lies in this page: > http://docs.python.org/3.3/library/stdtypes.html#string-methods > > > -- > James > >

Re: [Tutor] When to use multiprocessing Managers?

2014-03-03 Thread James Chapman
validation / error checking before submitting to the Queue. This could be important if the data going into the Queue was for example, user generated. Hmm, yeah I'd say question answered. Thanks eryksun. -- James On 1 March 2014 16:48, eryksun wrote: > On Fri, Feb 28, 2014 at 6:31 A

Re: [Tutor] c++ on python

2014-03-13 Thread James Chapman
Perhaps I should look into Cython as I'm currently working on a project that utilises a C API. I've been finding that getting the data types to be exactly what the C API is expecting to be the hardest part. With the original question in mind, here's an example calling into a C++ external C API:

Re: [Tutor] mixing 64 bit and 32 bit

2014-03-21 Thread James Chapman
Depending on what you're doing you could run into problems. Areas that have been challenging for me in the past: * Loading 64bit compiled .dll in a 32bit Python environment and vice versa. * Reading registry entries. MS tried to be clever by introducing the Wow6432Node reg key. And I'm sure there

Re: [Tutor] How can I let the Python Console display more decimal precision?

2014-07-01 Thread James Chapman
You could just initialise your variables with float() >>> float(26)/float(12) 2.1665 >>> varA = float(26) >>> varB = float(12) >>> varA/varB 2.1665 And so on... In fact, you only need to initialise one variable with float for this to work: >>> varA = float(26) >>> varB

Re: [Tutor] While Loop and Threads

2014-07-14 Thread James Chapman
Multi-threading takes practice! Are you using an event object to signal the thread should exit? I'm guessing you're just using a bool which is why it does not work. See: https://docs.python.org/3.4/library/threading.html#event-objects I'm very short on time and the moment and therefore can't moc

Re: [Tutor] While Loop and Threads

2014-07-14 Thread James Chapman
g_threadStop") g_threadStop.set() time.sleep(3) print("Main thread exiting...") if __name__ == '__main__': main() -- James On 14 July 2014 19:03, James Chapman wrote: > Multi-threading takes practice! > > Are you using an event object to s

Re: [Tutor] While Loop and Threads

2014-07-15 Thread James Chapman
; time_finish - >actually that is the way it is in original code. >2. dealing with the counter in the GTK main loop since it's main use >is for GTK display of the timer. > > But let's now follow your advice and leave GTK out for a while and keep &

Re: [Tutor] While Loop and Threads

2014-07-15 Thread James Chapman
used as an exit mechanism for normal operation. Where to place the timer is up to you. Another thread is an option, but is it necessary? Overhead needs to be considered. -- James On 15 July 2014 14:14, James Chapman wrote: > So if I understand this correctly, you want to start a thread and

Re: [Tutor] Does the user need to install Python, when we deploy our c++ products using python?

2014-12-11 Thread James Chapman
x27;m unsure of. -- James On 11 December 2014 at 11:39, James Chapman wrote: > > On 2 December 2014 at 20:28, gordon zhang > wrote: > >> >> >> I downloaded python 3.4.2 for c++ and create a vc++ project using python, >> but I have no idea what python

Re: [Tutor] Does the user need to install Python, when we deploy our c++ products using python?

2014-12-11 Thread James Chapman
On 2 December 2014 at 20:28, gordon zhang wrote: > > > I downloaded python 3.4.2 for c++ and create a vc++ project using python, > but I have no idea what python dlls and other stuff needed to deploy the > products. > > I know if we put Python34.dll and Python.dll in the folder of executable, > i

Re: [Tutor] While Loop Help

2014-12-11 Thread James Chapman
While Alan has given you a far better solution, I feel someone should mention the break statement as you will likely come across it a lot, and it is quite an important flow control statement. You could add a break statement to the else which would break out of the while loop. https://docs.python.o

Re: [Tutor] Python 3.4.1 ImportError Linux

2014-12-16 Thread James Chapman
cd .. Terminal (~/lorem): python3 app/main.py import statement is relative to pwd. -- James On 16 December 2014 at 14:18, Juan Christian wrote: > > Python 3.4.1 > Fedora 21 Server > > My paths: > ~/lorem > ~/lorem/app > ~/lorem/core > > I want to execute: ~/lorem/app/main.py > > Terminal (~/l

Re: [Tutor] Python 3.4.1 ImportError Linux

2014-12-16 Thread James Chapman
> Further to my last email, here's some reading regarding Python Paths > > http://www.stereoplex.com/blog/understanding-imports-and-pythonpath ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/m

Re: [Tutor] Assistance with UnicodeDecodeError

2015-02-04 Thread James Chapman
> > I am trying to scrap text from a website using Python 2.7 in windows 8 and > i am getting this error *"**UnicodeDecodeError: 'charmap codec can't encode > character u'\u2014 in position 11231 character maps to "* > > For starters, move away from Python 2 unless you have a good reason to use it.

Re: [Tutor] Assistance with UnicodeDecodeError

2015-02-04 Thread James Chapman
Actually, it's more likely that the char you are grabbing is UTF-16 not UTF-8 which is moving into the double byte... * An assumption based on the following output: >>> u = u'\u2014' >>> s = u.encode("utf-16") >>> print(s) ■¶ >>> s = u.encode("utf-32") >>> print(s) ■ ¶ >>> s = u.encode("utf-16L

Re: [Tutor] mySQL and Python

2015-02-18 Thread James Chapman
One of my pet hates about this list... "This is a tutor list, your question is out of scope". Sure there might be better places to seek answers, and sure maybe the first responder doesn't know the answer, but that's not a reason to respond with that phrase. This list is a called python tutor, not p

Re: [Tutor] Topic focus of ‘python-tutor’ (was: mySQL and Python)

2015-02-19 Thread James Chapman
Long-ish reply, but please bear with me. To quote the list description "This list is for folks who want to ask questions regarding how to learn computer programming with the Python language and its standard library." While MySQL modules are not part of the standard library, consider the following

Re: [Tutor] Windows Memory Basics

2017-10-17 Thread James Chapman
We're heading into advanced territory here and I might get told off but... Consider this C++ program for a second, it has a struct with different types of variables which sit next to each other in memory. When you print the byte values of the struct, you can see that there is no easy way to know wh

Re: [Tutor] How to debug a memory leak in a wsgi application?

2017-12-13 Thread James Chapman
Why pymalloc? I presume this means you're using ctypes which means I have more questions. If you're allocating your own blocks of memory then you need to free them too. IE, does each call to pymalloc have a corresponding call to pyfree? Is the overhead of pythons built in malloc really a problem?

Re: [Tutor] How to debug a memory leak in a wsgi application?

2017-12-14 Thread James Chapman
James On 13 December 2017 at 18:30, Etienne Robillard wrote: > Hi James, > > Thank for your reply. Are you suggesting that under Linux the malloc() > glibc library call is more memory efficient than using pymalloc? > > Best regards, > > Etienne > > Le 2017-12-13

Re: [Tutor] How to debug a memory leak in a wsgi application?

2017-12-14 Thread James Chapman
​Ah OK, now I understand why you mentioned pymalloc to begin with. I'm not familiar with uWSGI or cython. That said, why do you think it's uWSGI causing a leak? It seems unlikely. Python projects can grow in size if you're not dereferencing objects... (see https://f0rki.at/hunting-memory-leaks-in-

Re: [Tutor] When do you know you're ready to start applying for jobs?

2017-12-19 Thread James Chapman
Why has no one mentioned Github/Gitlab? Set up a free account on either or both platforms, and start committing your code. When applying for jobs potential employers will often want to see what you're capable of even before inviting you for an interview, and many will ask for a github page to see

Re: [Tutor] calling printf() in a C language DLL using ctypes.CDLL

2018-05-09 Thread James Chapman
A long time ago when I was working with Python and DLLs I slapped together a basic and ugly example. You can find it here: https://github.com/James-Chapman/python-code-snippets/ tree/master/DLL_C_funcs_w_callbacks The whole thing should load into Visual Studio. I can't guarantee that it wor