Re: ctype C library call always returns 0 with Python3
On 19/05/2012 10:30, Johannes Bauer wrote: Even the example in the standard library fails: import ctypes libc = ctypes.cdll.LoadLibrary("/lib64/libc-2.14.1.so") print(libc.strchr("abcdef", ord("d"))) Always returns "0". I think there may be two problems with this code: (1) You are using a 64-bit system but, in the absence of a function prototype for strchr, ctypes will be passing and returning 32-bit types. To add prototype information put something like: libc.strchr.restype = ctypes.c_char_p libc.strchr.argtypes = [ctypes.c_char_p, c_int] before the call of strchr(). (2) In Python3 strings are not plain sequences of bytes by default. In your example try passing b"abcdef" instead of "abcdef". -- CMcP -- http://mail.python.org/mailman/listinfo/python-list
Re: Flask failure
> On 15 Jun 2018, at 16:19, T Berger wrote: > > I’m trying to build a webapp with flask. I installed flask, created a webapp > in IDLE, but when I tried testing it at my terminal, I got a huge error > message. This is the app: > > from flask import Flask > app = Flask(__name__) > @app.route('/') > def hello() -> str: > return 'Hello world from Flask!' > app.run() > > This is my command and the resulting error message, containing a warning in > red: > > Last login: Thu Jun 14 23:54:55 on ttys000 > 192:~ TamaraB$ cd Desktop/Webapp/ > 192:Webapp TamaraB$ python3 hello_flask.py > * Serving Flask app "hello_flask" (lazy loading) > * Environment: production >WARNING: Do not use the development server in a production environment. >Use a production WSGI server instead. > * Debug mode: off > Traceback (most recent call last): > File "hello_flask.py", line 6, in > app.run() > [snip] > File > "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py", > line 467, in server_bind > self.socket.bind(self.server_address) > OSError: [Errno 48] Address already in use > 192:Webapp TamaraB$ > > What went wrong? Did the instructions for running this Flask example mention anything about not using the standard HTTP port number (80)? I don’t know much about Flask but I expect it runs an HTTP server in order to serve your HTML content to clients. If it tries to use the standard port then it will likely find it is already in use or that you do not have permission to use it. — Colin -- https://mail.python.org/mailman/listinfo/python-list
Re: mac os core dump from detached process
> On 27 Apr 2015, at 10:21, Robin Becker wrote: > > I'm using the double fork exec model as exemplified in > > http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/ > > to run a django management command detached from any view. A database object > is used to store/update information about the process. The command does have > a log file and appears to work well on linux. > > However, on my developer colleague's mac using the django development server > the job ends suddenly without passing through the try except finally that's > supposed to capture information. > > I believe the only way it can do this is os._exit or an interrupt eg SIGSEGV > etc etc. > > Is it possible to get core dumps on the Mac for debugging purposes? Would > the detached process inherit flags etc etc from the starting process? I know > little about OS X/Mach. > My first thought would be to run Applications -> Utilities -> Console and look for a crash report under ‘User Diagnostic Reports’ in the sidebar. I’m not entirely sure what my second thought would be if there wasn’t a report there. — CMcP -- https://mail.python.org/mailman/listinfo/python-list
Re: [pysqlite] [ANN] pysqlite and APSW projects moved
On 2008-03-09 18:57:00 +, Gerhard Häring <[EMAIL PROTECTED]> said: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Gerhard Häring wrote: >> [...] APSW >> >> >> web:http://oss.itsystementwicklung.de/trac/apsw/ >> scm:Subversion: http://initd.org/svn/pysqlite/apsw/trunk/ > > That should have been http://oss.itsystementwicklung.de/svn/apsw/apsw/ > > - -- Gerhard > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.6 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iD8DBQFH1DL7dIO4ozGCH14RAq4gAJ9tZuB9qcPERBkGzKEVBEx8nybfXgCeK8cX > V7sH3uAskDDNBuxYG34vExI= > =IXOx > -END PGP SIGNATURE- I'm getting 404 Not Found for the 'corrected' apsw web page URL. Also, the subversion URL doesn't seem right either: $ svn co http://initd.org/svn/pysqlite/apsw/trunk/ apsw svn: PROPFIND request failed on '/svn/pysqlite/apsw/trunk' svn: PROPFIND of '/svn/pysqlite/apsw/trunk': 403 Forbidden (http://initd.org) Regards, -- CMcP -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Functions as Enum member values
Hi, According to the enum module's documentation an Enum-based enumeration's members can have values of any type: "Member values can be anything: int, str, etc.." I defined one with functions as member values. This seemed to work as long as the functions were defined ahead of the enumeration's definition. However I then noticed that my enumeration class was a bit weird: even although I could reference the enumeration's members individually by name I couldn't iterate through the members in the normal fashion - it seemed to have no members. Also, calling type() on a member gave the result instead of the expected . I am using Python 3.9.5 from python.org on macOS 11.4. Below is a small test script and its output. Are my expectations wrong or is there a problem with Enum? Regards, Colin --- from enum import Enum def connect_impl(): print("message from connect_impl()") def help_impl(): print("message from help_impl()") class Command1(Enum): CONNECT = 1 HELP = 2 class Command2(Enum): CONNECT = connect_impl HELP = help_impl if __name__ == "__main__": def print_enum(cls, mbr): print(f"{cls.__name__}\n type(): {type(Command1)}") print(f" type of enum member: {type(mbr)}") print(f" number of members: {len(cls)}") print(" enum members:") if len(cls) > 0: for c in cls: print(f"{c}") else: print("") print(f" dir(): {dir(cls)}") member_1 = Command1.HELP print_enum(Command1, member_1) print() member_2 = Command2.HELP print_enum(Command2, member_2) print() print("call Command2 member: ", end="") member_2() print() --- (qt6) % python3 try_enum.py Command1 type(): type of enum member: number of members: 2 enum members: Command1.CONNECT Command1.HELP dir(): ['CONNECT', 'HELP', '__class__', '__doc__', '__members__', '__module__'] Command2 type(): type of enum member: number of members: 0 enum members: dir(): ['__class__', '__doc__', '__members__', '__module__'] call Command2 member: message from help_impl() (qt6) % --- -- https://mail.python.org/mailman/listinfo/python-list
Re: Functions as Enum member values
> On 31 May 2021, at 18:24, Peter Otten <__pete...@web.de> wrote: > > On 31/05/2021 17:57, Colin McPhail via Python-list wrote: >> Hi, >> According to the enum module's documentation an Enum-based enumeration's >> members can have values of any type: >> "Member values can be anything: int, str, etc.." > > You didn't read the fineprint ;) > Ah, neither I did. > """ > The rules for what is allowed are as follows: names that start and end with a > single underscore are reserved by enum and cannot be used; all other > attributes defined within an enumeration will become members of this > enumeration, with the exception of special methods (__str__(), __add__(), > etc.), descriptors (methods are also descriptors), and variable names listed > in _ignore_ > """" > > Functions written in Python are descriptors and therefore cannot be used. > Builtin functions aren't, leading to the following somewhat surprising > difference: > > >>> def foo(self): print("foo") > > >>> class A(Enum): > x = foo # foo.__get__ exists -> foo is a descriptor > # the enum library assumes you are adding a > # method to your > # class, not an enumeration value. > > y = sum # no sum.__get__ attribute -> function > # treated as an enumeration value. > > >>> list(A) > [>] > >>> A.x > > >>> A.y > > > >>> A.y.x() > foo > Thank you for explaining it. Regards, Colin -- https://mail.python.org/mailman/listinfo/python-list
Re: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib
> On 7 Nov 2019, at 03:24, Veek M wrote: > > Could someone suggest some introductory reading material that will allow > me to use 'telnetlib' with 'ssl' or 'ssltelnet'. > (currently using Pan since Knode is dropped on Debian) > > I'm trying to write something that will download the NNTP headers over > TLS. > > The idea is to > 1. telnet to port 119, send 'CAPABILITIES\r\n' using telnetlib > 2. then switch to TLS using STARTTLS > 3. I tried just connecting to port 119 using a new TLS connection NOT > OVER telnet and it didn't work. Apparently you need to pass the TLS > context to telnetlib or vice versa. > ... Any reason you're not using nntplib from the Python Standard Library? It supports the STARTTLS command. If you don't want to use nntplib you could look at its code to see how it works. -- Colin -- https://mail.python.org/mailman/listinfo/python-list
Re: How do I place a preset into the text box?
Hi Steve, > On 28 Aug 2020, at 11:03, Steve wrote: > > > The following program compiles but does not quite do what I would like it to > do. Line 19 is the preset information but I do not seem to be able to get it > into the form by code. My purpose is to let the user make changes without > having to re-enter the entire code. I'm no Tk expert but does the following do what you want? (Strictly speaking, the parentheses in ("1234-abcd") are not wrong just unnecessary.) #=== import tkinter as tk from tkinter import ttk import sys window = tk.Tk() window.title("Python Tkinter Text Box") window.minsize(600,400) def Submit(): label.configure(text= 'The new code is: ' + NewCode.get()) def ClickExit(): #This exit closes the program but the form remains and is still active. # I want only to close the form. print("Exiting") #sys.exit() window.destroy() #OldCode = ("1234-abcd") OldCode = "1234-abcd" label = ttk.Label(window, text = "Enter the new code") label.grid(column = 1, row = 1) #NewCode = tk.StringVar() NewCode = tk.StringVar(value=OldCode) CodeEntered = ttk.Entry(window, width = 15, textvariable = NewCode) CodeEntered.grid(column = 2, row = 3) button = ttk.Button(window, text = "Submit", command = Submit) button.grid(column= 2, row = 5) button = ttk.Button(window, text = "Quit", command = ClickExit) button.grid(column= 2, row = 7) window.mainloop() x = (NewCode.get()) print("The new code entered is: " + x) #= Regards, Colin -- https://mail.python.org/mailman/listinfo/python-list