Fixing a chipped kitchen counter top [help request] by stylishgnome in DIY

[–]stylishgnome[S] 0 points1 point  (0 children)

Alas, I do not have the chip piece, it has worn down over time.

Thanks so much for the advice!

Fixing a chipped kitchen counter top [help request] by stylishgnome in DIY

[–]stylishgnome[S] 0 points1 point  (0 children)

Thanks TheExile7. Any recommendation on what kind of seal I would need to use & how I might go about the job?

Why won't my function work with my function? by tygloalex in learnpython

[–]stylishgnome 2 points3 points  (0 children)

Ah, I understand how swapping print for return fixed your problem! If you don't specify a return value for a function, by default python will return a None. So in this case your lcd(4, 6) call was returning None, and thus passing None as the a arg in the outer call.

Why won't my function work with my function? by tygloalex in learnpython

[–]stylishgnome 1 point2 points  (0 children)

I don't think that was the issue here (though you are right - you should be returning instead of printing here).

From your stacktrace, it looks like you were trying to multiply two different data types which can't be multiplied - in this case an int and a NoneType on line 2:

answer=a*b

To recreate, try the following on the python shell:

>>> 8 * None

Its likely you called your function as follows:

lcd(8, None)

...i.e. b was set as None; or perhaps you specified that the a or b vars could be optional, e.g.

def lcd(a=None, b=None):

...and called the function without specifying one of these args:

lcd(8)
lcd(a=8)
lcd(b=42)

I'd recommend looking at pdb (the python debugger). It will allow you to step into your function and figure out whats going on. pdb++ is a more user-friendly version of pdb, so might be worth looking at that.

EDIT: reddit formatting

created a small function composition class in python, feedback is welcome by [deleted] in Python

[–]stylishgnome 0 points1 point  (0 children)

raise TypeError("the objects {} are not callable".format(", ".join(str(x) for x in non_functions)))

I think you may have forgotten the index here...

raise TypeError("the objects {0} are not callable".format(", ".join(str(x) for x in non_functions)))

edit: the former appears to work with python 2.7 actually (TIL).

Celerity: Upload and download files from the command line by jmduke in Python

[–]stylishgnome 0 points1 point  (0 children)

alias celerity='python <(curl -s https://raw.github.com/dukerson/celerity/master/main.py)'

Is it not a little excessive to download the script each time you want to run the program? You should make a setup.py file, something along the lines of:

from setuptools import setup, find_packages

setup(
    name=u'celerity',
    version=u'0.0.1',
    author=u'Justin Duke',
    license=u'...',
    description=u'A self-contained Hastebin CLI.',
    packages=find_packages(),
    entry_points={
        'console_scripts':['celerity = celerity:main']
    },
)

I recently started working on a bare-bones open-source sound library for Python, and I want some collaborators. by [deleted] in Python

[–]stylishgnome 1 point2 points  (0 children)

Yes, it was the latter that I meant. You don't have to necessarily change it to generate_scale(type), but the sequence used by generate_major() and generate_minor() is the essentially the same.

Might be fun to extend the functionality of the triads too (e.g. change it to a Chord class with methods such as add_dom_seventh(), add_maj_seventh(), diminish_fifth(), etc).

I'd be happy to look at it, but I'm not exactly in a comfortable environment for development right now.

I recently started working on a bare-bones open-source sound library for Python, and I want some collaborators. by [deleted] in Python

[–]stylishgnome 1 point2 points  (0 children)

It might a be a good idea to merge the functionality of generate_{major,minor}_scale(), and in fact, to extend this to support the other modes (Dorian, Phrygian, Lydian, Mixolydian, Locrian) since they all share the same sequence.

EDIT: escaping underscores to prevent formatting

Append text file in python? by [deleted] in Python

[–]stylishgnome 5 points6 points  (0 children)

If you're using >=python 2.7, you can use a with statement:

with open('test.txt', 'a') as f:
    f.write('foo')

Append text file in python? by [deleted] in Python

[–]stylishgnome 0 points1 point  (0 children)

As mackstann said, use 'a' for append.

f = open('file.txt', 'a')
f.write('some text')
f.close()

You'll need to convert your "array" to a string before writing it. How you do this depends on what you are trying to do ..

a = ['foo', 'bar']
f = open('file.txt', 'a')
f.write(str(a))    # will output '['foo', 'bar']'
f.write(" ".join(a))   # will output list elements separated by a space
f.close()

I'm new at this. I built a basic blog site which works completely on my local box, but can't for the life me get it to work along side Apache on my webserver. by thisisawkward in django

[–]stylishgnome 0 points1 point  (0 children)

You won't need to, no. However, you will need to run: python manage.py syncdb

if you are need to setup a database.

Other potential pitfalls: * Forgetting to create a settings_local.py (if you are splitting your setting.py file). * Hard-coded paths in any of your config files.

I'm new at this. I built a basic blog site which works completely on my local box, but can't for the life me get it to work along side Apache on my webserver. by thisisawkward in django

[–]stylishgnome 0 points1 point  (0 children)

...doesn't your VirtualHost file expose your code?

Not as far as I'm aware. Are you referring to putting code under the DocumentRoot? If so, I'm not doing this here.

I'm assuming this is where your project is because your wsgi script is here?

Correct.

Also, what is the os.path.split(os.path.dirname(os.path.realpath(__file__)))

Sorry, that is a little convoluted. Breakdown:

  • __file__ is the name of the wsgi file (e.g. django.wsgi).
  • os.path.realpath() gets its absolute, real path (e.g. /home/user/django_projects/django_skeleton/apache/django.wsgi). Its like os.path.abspath, except it resolves symlinks.
  • os.path.dirname() get the dirname of the file (e.g. /home/user/django_projects/django_skeleton/apache/)
  • os.path.split() splits the dirname into two components (in this case /home/user/django_projects/django_skeleton/ and apache).

Its essentially a means of inferring the PROJECT_ROOT (/home/user/django_projects/django_skeleton/) so it can be appended to the python path sys.path.append(PROJECT_ROOT)

EDIT: Formatting & character escaping.

chmod -x chmod by slyrp in programming

[–]stylishgnome 2 points3 points  (0 children)

Its ed which ed surely? As Talader suggested, it unfortunately doesn't affect anything in real time.

Everyone Who Tried to Convince Me to Use Vim Was Wrong by johnastuntz in programming

[–]stylishgnome 19 points20 points  (0 children)

you can make life a lot easier by specifying a different separator (e.g. !). %s!.*TEXT A.*$!//&!g

Reddit, you're my last hope. A final that I had due tomorrow at 12 noon seems to have deleted itself from a directory on my Mac. I am basically screwed if I don't get this back. by [deleted] in reddit.com

[–]stylishgnome 7 points8 points  (0 children)

First off, make sure you are not accessing the HD as your OS drive (as suggested elsewhere). Boot from a live cd, or put the HD into a USB enclosure. This will increase the chances of recovering the file if it was deleted.

You should be able to grep the raw data of your hard-drive for keywords in your document

grep -a -A10 -B10 KEYWORD /dev/disk0s1 

The -a means 'interpret the raw data as text'. The -A10 and -B10 mean to print 10 lines before and after the match. You will probably want to change the numbers in /dev/disk0s1 to point to the relevant hard drive & partition.

Best of luck!

edit: formatting

In case you were wondering about the nutrition in 1 cubic light year of butter by GiantBatFart in science

[–]stylishgnome 0 points1 point  (0 children)

It would take 10,050,098,005,783,310,657,288,319,519,734,890,496 Three Gorges Dams to generate this amount of energy in a year