restructured to match distribution profile
This commit is contained in:
parent
1b7b32d4e2
commit
d27da38aa7
|
@ -2,3 +2,10 @@ python_data_structures
|
||||||
======================
|
======================
|
||||||
|
|
||||||
Some useful python data structures / concepts
|
Some useful python data structures / concepts
|
||||||
|
|
||||||
|
distributions can be found on pypi:
|
||||||
|
|
||||||
|
* https://pypi.python.org/pypi?:action=display&name=multi_key_dict
|
||||||
|
* https://pypi.python.org/pypi?:action=display&name=text_progress_bar
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
setup.py bdist_wininst sdist = to build it
|
||||||
|
|
||||||
|
python setup.py register bdist bdist_wininst upload = uploading
|
|
@ -1,97 +0,0 @@
|
||||||
'''
|
|
||||||
Created on 9 Jun 2013
|
|
||||||
|
|
||||||
@author: lukasz.forynski
|
|
||||||
|
|
||||||
@brief: Function to get some trace information about the exception-rising code,
|
|
||||||
when called from exception handler.
|
|
||||||
|
|
||||||
This information includes:
|
|
||||||
- module name
|
|
||||||
- class name (if exception executed in the method)
|
|
||||||
- line number
|
|
||||||
|
|
||||||
This might be more useful (and logical) than what's provided with traceback
|
|
||||||
which gives filenames, line numbers and code snippets
|
|
||||||
|
|
||||||
https://github.com/formiaczek/python_data_structures
|
|
||||||
___________________________________
|
|
||||||
|
|
||||||
Copyright (c) 2013 Lukasz Forynski <lukasz.forynski@gmail.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
publish, distribute, sub-license, and/or sell copies of the Software, and to permit persons
|
|
||||||
to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
- The above copyright notice and this permission notice shall be included in all copies
|
|
||||||
or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
import inspect
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def raising_code_info():
|
|
||||||
code_info = ''
|
|
||||||
try:
|
|
||||||
frames = inspect.trace()
|
|
||||||
if(len(frames)):
|
|
||||||
full_method_name = frames[0][4][0].rstrip('\n\r').strip()
|
|
||||||
line_number = frames[1][2]
|
|
||||||
module_name = frames[0][0].f_globals['__name__']
|
|
||||||
if(module_name == '__main__'):
|
|
||||||
module_name = os.path.basename(sys.argv[0]).replace('.py','')
|
|
||||||
class_name = ''
|
|
||||||
obj_name_dot_method = full_method_name.split('.', 1)
|
|
||||||
if len(obj_name_dot_method) > 1:
|
|
||||||
obj_name, full_method_name = obj_name_dot_method
|
|
||||||
try:
|
|
||||||
class_name = frames[0][0].f_locals[obj_name].__class__.__name__
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
method_name = module_name + '.'
|
|
||||||
if len(class_name) > 0:
|
|
||||||
method_name += class_name + '.'
|
|
||||||
method_name += full_method_name
|
|
||||||
code_info = '%s, line %d' % (method_name, line_number)
|
|
||||||
finally:
|
|
||||||
del frames
|
|
||||||
sys.exc_clear()
|
|
||||||
return code_info
|
|
||||||
|
|
||||||
|
|
||||||
def function1():
|
|
||||||
print 1/0
|
|
||||||
|
|
||||||
class AClass(object):
|
|
||||||
def method2(self):
|
|
||||||
a = []
|
|
||||||
a[3] = 1
|
|
||||||
|
|
||||||
def try_it_out():
|
|
||||||
# try it with a function
|
|
||||||
try:
|
|
||||||
function1()
|
|
||||||
except Exception, what:
|
|
||||||
print '%s: \"%s\"' % (raising_code_info(), what)
|
|
||||||
|
|
||||||
# try it with a method
|
|
||||||
try:
|
|
||||||
my_obj_name = AClass()
|
|
||||||
my_obj_name.method2()
|
|
||||||
except Exception, what:
|
|
||||||
print '%s: \"%s\"' % (raising_code_info(), what)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try_it_out()
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
multi_key_dict
|
||||||
|
======================
|
||||||
|
|
||||||
|
|
||||||
|
Implementation of a multi-key dictionary.
|
||||||
|
|
||||||
|
This kind of dictionary has a similar interface to the standard dictionary,
|
||||||
|
|
||||||
|
and indeed if used with single key key elements - it's behaviour is the same as for a standard dict.
|
||||||
|
|
||||||
|
However it also allows for creation of elements using multiple keys (using tuples/lists). Such elements can be accessed using either of those keys (e.g for read/update/deletion).
|
||||||
|
Multi-key dict provides also extended interface for iterating over items and keys (e.g. by the key type), which might be useful when creating, e.g. dictionaries with index-name key pair allowing to iterate over items using either: names or indexes.
|
||||||
|
It can be useful for many many other similar use-cases, and there is no limit to the number of keys used to map to the value.
|
||||||
|
|
||||||
|
There are also methods to get other keys that map to the same element and others. Refer to examples and test code to see it in action.
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!python
|
||||||
|
|
||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
long_descr=''
|
||||||
|
|
||||||
|
with open('README.txt') as readme:
|
||||||
|
long_descr = readme.read()
|
||||||
|
|
||||||
|
setup(name='multi_key_dict',
|
||||||
|
version='1.0.2',
|
||||||
|
description='Multi key dictionary implementation',
|
||||||
|
author='Lukasz Forynski',
|
||||||
|
author_email='lukasz.forynski@gmail.com',
|
||||||
|
url='https://github.com/formiaczek/python_data_structures',
|
||||||
|
py_modules=['multi_key_dict'],
|
||||||
|
license=['License :: OSI Approved :: MIT License (http://opensource.org/licenses/MIT)'],
|
||||||
|
long_description=long_descr,
|
||||||
|
classifiers=[
|
||||||
|
'Programming Language :: Python',
|
||||||
|
'License :: OSI Approved :: MIT License',
|
||||||
|
'Development Status :: 4 - Beta',
|
||||||
|
'Operating System :: OS Independent',
|
||||||
|
'Intended Audience :: Developers',
|
||||||
|
'Topic :: Software Development :: Libraries :: Python Modules'
|
||||||
|
]
|
||||||
|
)
|
|
@ -0,0 +1,10 @@
|
||||||
|
text_progress_bar
|
||||||
|
======================
|
||||||
|
|
||||||
|
|
||||||
|
Implementation of a simple text progress bar.
|
||||||
|
|
||||||
|
It looks something like this:
|
||||||
|
|
||||||
|
[================..............] : downloading xyz (186/335)
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!python
|
||||||
|
|
||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
long_descr=''
|
||||||
|
|
||||||
|
with open('README.txt') as readme:
|
||||||
|
long_descr = readme.read()
|
||||||
|
|
||||||
|
setup(name='text_progress_bar',
|
||||||
|
version='1.0.1',
|
||||||
|
description='Simple text progress bar',
|
||||||
|
author='Lukasz Forynski',
|
||||||
|
author_email='lukasz.forynski@gmail.com',
|
||||||
|
url='https://github.com/formiaczek/python_data_structures',
|
||||||
|
py_modules=['text_progress_bar'],
|
||||||
|
license=['License :: OSI Approved :: MIT License (http://opensource.org/licenses/MIT)'],
|
||||||
|
long_description=long_descr,
|
||||||
|
classifiers=[
|
||||||
|
'Programming Language :: Python',
|
||||||
|
'License :: OSI Approved :: MIT License',
|
||||||
|
'Development Status :: 4 - Beta',
|
||||||
|
'Operating System :: OS Independent',
|
||||||
|
'Intended Audience :: Developers',
|
||||||
|
'Topic :: Software Development :: Libraries :: Python Modules'
|
||||||
|
]
|
||||||
|
)
|
Loading…
Reference in New Issue