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 works

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] 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

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

2017-12-14 Thread James Chapman
On 13 December 2017 at 18:30, Etienne Robillard <tkad...@yandex.com> 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 > >

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

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

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

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

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] 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] 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

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] 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

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-16LE) print(s) ¶ s =

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 undefined* For starters, move away from Python 2 unless you have a good reason to use

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 juan0christ...@gmail.com wrote: Python 3.4.1 Fedora 21 Server My paths: ~/lorem ~/lorem/app ~/lorem/core I want to execute: ~/lorem/app/main.py

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:

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

2014-12-11 Thread James Chapman
unsure of. -- James On 11 December 2014 at 11:39, James Chapman ja...@uplinkzero.com wrote: On 2 December 2014 at 20:28, gordon zhang zhanggordon...@gmail.com 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

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 zhanggordon...@gmail.com 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

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.

Re: [Tutor] While Loop and Threads

2014-07-15 Thread James Chapman
. Is that correct? If yes, would there be an obvious advantage to either using GTK main loop or dealing with another thread? 2014-07-14 20:24 GMT+02:00 James Chapman ja...@uplinkzero.com: OK, so I mocked up an example now... import time import threading g_threadStop = threading.Event() def

Re: [Tutor] While Loop and Threads

2014-07-15 Thread James Chapman
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 ja...@uplinkzero.com wrote: So if I understand this correctly, you want to start

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

Re: [Tutor] While Loop and Threads

2014-07-14 Thread James Chapman
exiting...) if __name__ == '__main__': main() -- James On 14 July 2014 19:03, James Chapman ja...@uplinkzero.com wrote: 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

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 = 12 varA/varB

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

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] When to use multiprocessing Managers?

2014-03-03 Thread James Chapman
AM, James Chapman ja...@uplinkzero.com wrote: log_Q = multiprocessing.Queue() This is a Queue from multiprocessing.queues. It uses system resources (e.g. a semaphore for the queue capacity) that can be shared with processes on the same machine. A value `put` in a queue.Queue is available

Re: [Tutor] When to use multiprocessing Managers?

2014-02-28 Thread James Chapman
James Chapman ja...@uplinkzero.com: 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

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 ja...@uplinkzero.com wrote: The answer lies in this page: http://docs.python.org/3.3/library/stdtypes.html#string-methods -- James On 28

[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

[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

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
will be substituted for some kind of assert lines ** FYI I'm using CPython 2.7.something -- James On 31 January 2014 12:57, eryksun eryk...@gmail.com wrote: On Fri, Jan 31, 2014 at 6:31 AM, James Chapman ja...@uplinkzero.com wrote: try: while self.attribute: time.sleep(1

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
D'Aprano st...@pearwood.info 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 run it past you. [...] class Infinite_Loop_Tutor_Question(object

Re: [Tutor] Mocking with mock in unit testing

2014-01-17 Thread James Chapman
, James Chapman ja...@uplinkzero.com wrote: In my unittest I don't want to run the ping command, (It might not be available on the build system) I merely want to check that a call to subprocess.Popen is made and that the parameters are what I expect? You can mock `Popen` where it's

Re: [Tutor] Mocking with mock in unit testing

2014-01-17 Thread James Chapman
January 2014 10:50, eryksun eryk...@gmail.com wrote: On Fri, Jan 17, 2014 at 4:58 AM, James Chapman ja...@uplinkzero.com wrote: import mock import unittest import pinger class Test_Pinger(unittest.TestCase): def test_ping_host_succeeds(self): pinger = pinger.Pinger

Re: [Tutor] Mocking with mock in unit testing

2014-01-17 Thread James Chapman
. -- James On 17 January 2014 11:23, Steven D'Aprano st...@pearwood.info 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 example looks like

Re: [Tutor] Mocking with mock in unit testing

2014-01-17 Thread James Chapman
On 17 January 2014 15:32, Steven D'Aprano st...@pearwood.info 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 st...@pearwood.info wrote: On Fri, Jan 17, 2014 at 09:58:06AM +, James Chapman wrote: [...] import

[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 =

[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 call

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(ublah£.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 Chapman wrote: Hi there python

Re: [Tutor] Opening filenames with unicode characters

2012-06-28 Thread James Chapman
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's dynamic. In other words, how do I rewrite open(ublah

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
: 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 -- although it might well be very relevant -- I'm going to ignore

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,

[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

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 turning here because