There is a security technique known as code signing. It basically generates a certificate for your code. This certificate first certifies the author of the code. Second, it has a value generated from the code. This value is unique to that code. If any changes are made to the code, then the certificate is invalidated. I'm just not sure how to go about doing it. I'd like to do my own. There have a paid certificate authority services, but I don't have the money to pay. There are free certificate authority services, but I'm not sure exactly which service I'd …

Member Avatar
Member Avatar
+0 forum 7

I had been wanting to write an IRC bot with asynchronous IO for a while. My bot responds to pings, but can be extended by defining functions and registering them to get called when the bot receives certain commands. My bot uses the RFC 1459 USER command and parameters, but can be made to comply with RFC 2812 by replacing my on_connect function with a compliant one. Here is what I wrote based on the asyncore and asynchat modules: [code=PYTHON]import asynchat import asyncore import collections import socket def parse(data): data = data.split(b' ') if data[0].startswith(b':'): #prefix present prefix = data[0][1:] …

Member Avatar
Member Avatar
+0 forum 1

I am doing some hobby coding regarding neural networks, and I was wondering if this is a correct and good use of abstract base classes or not. [code=PYTHON]import abc import collections import math import weakref class AbstractNeuron(metaclass=abc.ABCMeta): def __init__(self, weights, f=math.tanh, bias=1, biasWeight=0): self.weights = weights self.f = f self.bias = bias self.biasWeight = biasWeight def __call__(self, inputs): return self.activate(inputs) @abc.abstractmethod def activate(self, inputs): raise NotImplementedError class MappingNeuron(AbstractNeuron): def __init__(self, weights=None, f=math.tanh, bias=1, biasWeight=0): if weights is None: weights = collections.defaultdict(int) super().__init__(weights, f, bias, biasWeight) def activate(self, inputs): return self.f(math.fsum(inputs[key] * self.weights[key] for key in inputs.keys()) + self.bias * self.biasWeight) …

Member Avatar
Member Avatar
+0 forum 1

I'm working on a project where I would like to compare collections of words, but I have additional constraints I need to account for. The collections are like a set in that order doesn't matter for the comparison. However, in my problem equal elements are significant. E.g. the collection of "foo", "bar", "baz" would not be the same as the collection of "baz", "foo", "bar", "baz". However, the collection of "baz", "foo", "bar", "baz" would be the same as the collection of "bar", "baz", "foo", "baz". Additionally, the collection itself must be hashable. Thank you for reading.

Member Avatar
Member Avatar
+0 forum 3

I'm interested in a generic event system for Python. I've searched the forum for similar topics, and I've searched the web for existing implementations. I haven't found exactly what I'm looking for. I'm familiar with the Observer pattern. However, my implementation and other implementations lack strong support for concurrency and scheduling. Do you know of anything that fits the bill or can you help me create an implementation? I want to use this for simulations and games.

Member Avatar
Member Avatar
+0 forum 6

I know that certain functions will check the script's or module's current directory for the file if no path is specified. [code=PYTHON]open('test.txt')[/code] If that script is run and test.txt is in the same directory that will open the correct file. However, if I try to import that module it doesn't work because presumably the path is different. How can I get this to work proper?

Member Avatar
Member Avatar
+0 forum 9

U.S. Military Weapons Inscribed With Secret 'Jesus' Bible Codes Pentagon Supplier for Rifle Sights Says It Has 'Always' Added New Testament References [URL="http://abcnews.go.com/Blotter/us-military-weapons-inscribed-secret-jesus-bible-codes/story?id=9575794"]http://abcnews.go.com/Blotter/us-military-weapons-inscribed-secret-jesus-bible-codes/story?id=9575794[/URL] I saw this. I think this is wrong.

Member Avatar
Member Avatar
+1 forum 48

I'm having a problem with 'os.path.getmtime'. I've been doing some research into generating '.pyc' files and I am able to retrieve the source modification time (in seconds) as recorded in the '.pyc' file. It is merely the second set of four bytes unpacked as a long integer. [code=Python] import random, sys, os, struct #Points to the random.pyc module. testfilepath = os.path.join(sys.prefix, 'lib', 'random' + os.extsep + 'pyc') istream = open(testfilepath, 'rb') #Read and discard the first four bytes (the magic pyc identifier). istream.read(4) #The last modification time of the source according to the file. modtime = istream.read(4) istream.close() #Convert the …

Member Avatar
Member Avatar
+0 forum 10

I was wondering if anyone knows of any resources about building a custom importer. I've found this: [url]http://www.doughellmann.com/PyMOTW/sys/imports.html[/url]. I am also aware of PEP 302 and PEP 369 and imp and importlib. Are there any other resources I might need?

Member Avatar
Member Avatar
+1 forum 4

I've seen these in documentation, namely in the "importlib" documentation for Python 3.1, and I'm wondering what the difference is between a "universal newline" and a "standard newline", if any. I know it has to do with the byte sequence that is used to represent newlines, and I think universal newlines are simply a single linefeed byte, but I'm not sure about standard newlines. Are they simply the form the host machine uses?

Member Avatar
Member Avatar
+0 forum 4

I'm using the code module to add an interactive interpreter to an object. This object has an interact method that when called creates an interactive interpreter with the object's dictionary as the namespace for the interpreter. When done interacting with the object, I want the "exit" function to return execution back to the original thread of execution. Here is the initial code. [code=Python]from uuid import uuid4 import code ANONYMOUS = None UUID = 0 class Agent: def __init__(self, name = UUID): self.__uuid = uuid4() if name == UUID: name = self.__uuid self.__name = name @property def uuid(self): return self.__uuid @property …

Member Avatar
Member Avatar
+0 forum 1

I'm just wondering if it is possible to import a module as an object attribute. The basic description of what I want to accomplish is that I'm creating a software agent object. This agent will have a set of abilities (functions), but I don't know what these are ahead of time. Logically, it is simplest to encapsulate these abilities in a module, and then have the agent import it. Then it would have access to these abilities. This would also allow it to use the standard modules or any other previously developed modules. Another benefit is that each object has …

Member Avatar
Member Avatar
+1 forum 18

And I can't get anything I write to work. I'm so far off course I think I just need a working example of import hooks in action. I've looked for examples on the Internet, but they only show what looks like correct code. They never show that code in action. They never try to import something and show what their hook does.

Member Avatar
Member Avatar
+0 forum 3

(A quine is a program that produces its own source as its output, typically to a file.) [CODE=Python]import sys ifile = sys.argv[0] counter = 0 istream = open(ifile) source = istream.readlines() source[2] = 'counter = ' + str(counter + 1) + '\n' if counter == 0: original = str(ifile) source.insert(5, 'original = r'' + str(original) + ''\n') istream.close() ofile = list(original) ofile.insert(-3, str(counter)) ofile = ''.join(ofile) ostream = open(ofile, 'w') ostream.writelines(source) ostream.close()[/CODE] It is a naive implementation in that it depends on code that assumes that the new executables are created in and stay in the same directory as the …

Member Avatar
Member Avatar
+0 forum 1

I'm thinking about writing a small command line directory management program in Python. The most basic functionality I want is to be able to compare the the files in a directory and sub-directory, and if there are any duplicates then delete the lower most duplicate. I all ready have a basic idea of how to accomplish that. Merely hash both files and compare the hash values. If the hash values are equivalent, then they are the same. However, I'm not sure on the specifics of how to accomplish it. I know the data has to be read from each file …

Member Avatar
Member Avatar
+0 forum 3

Lately I've been writing a lot of code involving the creation of new objects, and I quickly come to find that Python almost always creates a reference to an object instead of a new object. I understand the importance of conserving memory usage, but in this instance I actually need a true copy. My problem is that I have yet to find anything in Python that can quickly generate a true copy of all objects. I am aware of the copy module, but it will not copy certain objects I need to copy. I have had some success experimenting with …

Member Avatar
Member Avatar
+0 forum 10

I'm wondering if it's possible to change the border color of a tkinter entry widget border. I don't think it is, because no such option exists in relevant documentation. You can change the width, but that just results in the whitespace being recessed - creating a raised 3d border. If it can't be done, would it be more valid to use a frame around the widget? Is it possible to combine the border width and a frame to create a good appearance? Thank you.

Member Avatar
Member Avatar
+0 forum 2

Hello. I'm lrh9, a new user. This is my first time visiting these forums. I've posted on [url]www.programmingforums.org[/url] under the same user name. I'm a hobbyist and amateur computer programmer. My primary languages are C++, a custom scripting language for Windows named AutoHotkey, and Python which I've just started out learning but am determined to learn. I learned some Visual Basic 6 - my first programming language -in high school, but I've forgotten most of it. I've also used programming features of graphing calculators to a small extent. I think I'm naturally inclined to computer programming. When I was a …

Member Avatar
Member Avatar
+1 forum 2

So I'm interested in learning about data validation. Especially in Python. Python all ready has several common idioms for data validation. There are several statements that evaluate data. For instance, isinstance(object, classinfo) will check that the given object is an instance of the class or type in classinfo. One idiom is that it is better to ask forgiveness than permission, which basically means it is better to try something and catch the errors instead of trying to force the data to be valid. The main language feature that supports this idiom is the try statement and its associated statements. It …

Member Avatar
Member Avatar
+0 forum 6

I want to call another object's methods from another object, and I have no idea how. Can someone please help me? Thank you.

Member Avatar
Member Avatar
+0 forum 6

Is it a good idea to help people with object oriented software design and code? I'm asking this because most of the code here is written using the functional programming, and all could probably improve a little or a lot with object oriented design and coding. My first doubt about offering this type of assistance stems from the large amount of homework questions. Courses don't allow you to put advanced techniques in assignments and tests designed to understand the basic material. If you turn in a program written with classes while you're just beginning to learn about defining functions, you'll …

Member Avatar
Member Avatar
+0 forum 1

I always wondered how a programmer could efficiently generate a random number from a set* of numbers once and only once. I quickly realized the inefficient solution. Simply generate the number and if it equals one you have all ready generated then regenerate the number. Regenerating the number is a poor method. Especially in a small set or if you are going to exhaust the elements in the set. Today I realized a smarter solution. Instead of using random to generate a number that is in the set, use random to generate the index of a element in the set …

Member Avatar
Member Avatar
+0 forum 13

Out of curiosity, how would you reverse a string's case in Python? Make uppercase characters lowercase and lowercase characters uppercase. Here's the function for the naive implementation. [CODE] #!/usr/bin/env python def flip_case(input_string): temp_list = list(input_string) for index, character in enumerate(temp_list): if character.islower(): temp_list[index] = character.upper() else: temp_list[index] = character.lower() output_string = ''.join(temp_list) return output_string my_string = "AaBbCc" my_string = flip_case(my_string) print(my_string)[/CODE] The output is: [QUOTE]aAbBcC[/QUOTE] I'm thinking a smarter implementation would be to use a string's translate method. What do you think?

Member Avatar
Member Avatar
+0 forum 6

The End.