Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Alternatives to make in experiments automation?

I am posting this question here more for the type of community than for the language.

I am looking for an alternative to make for experiments automation. The experiments consist in data, python scripts that crunch the data and results. If a script change, I want only the associated part of the experiment to re-run, same if data change.

A very similar scenario is described in the software carpentry lesson: http://swcarpentry.github.io/make-novice/

Many make-like tools are designed just as build system and are a pain to adapt to my needs.

What tools do you know that are alternatives to make for non-compiling purposes?

/r/IPython
https://redd.it/4w5wmw
Kernel seems to be dead

I've installed the anaconda 3.5 package from the continuum website. When I am trying to do this

from skimage import data

the prompt is saying that "The kernel appears to have died. It will restart automatically."

/r/IPython
https://redd.it/4vxiq5
Generating the leftmost column of a table before the rest

Hey /r/django, I have a problem:

I need to create a table that looks like this

<table>
<tr>
<td>data0_from_array0</td>
<td>data0_from_array1</td>
</tr>
<tr>
<td>data1_from_array0</td>
<td>data1_from_array1</td>
</tr>
...etc
</table>

At the moment i have

<table>
<tr><td>Label: </td>{% for item in array0 %}<td>{{ item }}</td>{% endfor %}</tr>
<tr><td>Label2: </td>{% for item in array1 %}<td>{{ item }}</td>{% endfor %}</tr>
</table>

which presents the data "on the wrong axis", which doesn't work for my client.

The biggest problem is that I don't know how big the arrays can become so each row becomes far too wide or densely populated. There are only ever two arrays so I'd like to order them in *n* rows with two cells each instead of 2 rows with *n* cells each. Any pointers?

/r/django
https://redd.it/5j5lv2
[AF] Difficulties linking form to database using flask.

Hi,
I'm not sure how to go about linking my form to a database. How can i do this?
My code can be located here: https://github.com/richard0096/Application_Form

Apologies for the messiness of my code, I've just started programming!

Thanks for the help.

/r/flask
https://redd.it/5dnblb
Validating overlapping Date Ranges

Originally posted this in https://www.reddit.com/r/learnpython subreddit but I think I might get more help here.
(Edit - I didn't mean to make that line obnoxiously large)

Building off a question I asked here: https://www.reddit.com/r/learnpython/comments/5cgavm/django_model_prevent_overlapping_dates/

I'm at the point where my checks for overlapping terms for a single office work.

Now, I also need to include terms for people serving on a committee.

Some background: I've set up my project to have a model for Person, Candidate, Election, Office, and Term. A Person can become a Candidate who runs in an Election for a given Office and the winner serves a Term.

For single offices, this works pretty straightforward - we can only have one President, Secretary, Treasurer, etc. at a time. Testing for overlapping dates means seeing if the new start date and/or end date are within any other existing term.

However, we also have people who run for a seat on a five-person committee. So I have an office of "Committemember." They do not run for a given seat, but rather the top five vote getters get those five seats. So at any given time, there can be at most 5 people on the committee. But everyone may have different start/end dates. And there may be vacancies.

So let's say I enter in a new committee member with term dates 2000-01-01 to 2004-01-01. I need to know for every single date over those four years if there are already five people on the committee on that date. Over the course of this particular committee member's term, there may have been a lot of other committee members serving... for example, 16 if every other seat turned over every year. So I can't just count how many people served during that term. I need to know this by every date in that term.

If this algorithm gets too complicated, an alternate solution I was thinking of is in the database to have Committee Seat 1, Committee Seat 2, etc. But Elections are not held for specific seats, so I'd have to add a Seat field to my Term model. For things like President, Secretary, etc, the office and seat would be the same. For the committees, office would be Committeemember and seat would be Committee Seat 1 and so on, keeping in mind this is just a coercion to get the data to work, and not reflective of the real life system.

Any suggestions on the best way to tackle this?

(Also, I'm using SQLite to keep the database setup stuff simple. I think Postgres has a date range type which may make this all easier but would be another learning curve to set up the database and then figure out how to work with date ranges so I'd really like to use SQLite for now)


/r/djangolearning
https://redd.it/5iqsac
Panda user defined function help

I'm still new to Python and pandas. I know how to solve my problem in SQL, SAS, and R but that doesn't help me in python. I have a simple table I read in using pandas and I want to create a new field on the table based on a conditional assessment of an existing field.

import pandas as pd
table = pd.read_csv("c:/path/file.csv")
table.head(2)

recnum | ele1 | code
----|-----|-----
1|value|code1
2|value|code2

I want to create a 4th field on the table using a function that assesses the code field.

def myfunc(x):
if x = "val1": return "Code1"
elif x = "val2": return "Code2"

table['col4'] = map(lambda x: myfunc(table['col3']),axis = 1)

gives me an error. Trying apply instead of map gives me an error. So far google and stackoverflow searches have not helped.

/r/pystats
https://redd.it/4huh21
Encode Kernel Preference in Notebook

Hey,

I`m wondering, is it possible to somehow make sure, explicitly, that when your .ipynb file is opened it will open, let us say, the Julia ver 0.3.12 kernel? If so, how?

Background: Currently I'm writing Jupyter notebooks with the Julia ver 0.4.1 kernel running in the background, but I`d like the notebooks to open a ver 0.3.12 kernel automatically instead.

I could not find an explanation straight away so I opted to ask it myself here. Any help much appreciated!



/r/IPython
https://redd.it/4vxowt
405 Error on very simple code?

Hi guys!

Super confused as to why this isn't working!

from flask import Flask, request, render_template
import requests

app = Flask(__name__)

@app.route('/temperature', methods=['POST'])
def temperature():
zipcode = request.form['zip']
r = requests.get('http://api.openweathermap.org/data/2.5/weather?zip=' +zipcode+',us&appid=')
json_obj = r.text
return json_obj

@app.route('/')
def index():
return 'hi'

if __name__ == '__main__':
app.run(debug=True)


Why the hell isn't this working?!

edit: http://127.0.0.1:5000/temperature

this url is giving me the 405 error?

/r/flask
https://redd.it/5j8fgc
calling model.create() from the management shell works OK but calling it via a custom management command fails. can you help me work out why?

Here is the model and its create method:

class Sentence(models.Model):
text = models.CharField(max_length=140, unique=True)
created = models.DateTimeField(auto_now_add=True, auto_now=False)
ups = models.IntegerField(default=0)
downs = models.IntegerField(default=0)
score = models.IntegerField(default=0)
appearances = models.IntegerField(default=0)
last_appearance = models.DateTimeField(auto_now_add=False, auto_now=True)
tweeted = models.DateTimeField(auto_now_add=False, auto_now=False, blank=True, null=True)
dropped = models.DateTimeField(auto_now_add=False, auto_now=False, blank=True, null=True)

objects = querysets.SentenceQuerySet.as_manager()

@classmethod
def create(cls):
with open(TEXT_MODEL_JSON_FILE, 'r') as json_file:
model_data = json.loads(json_file.read())
reconstituted_model = markovify.Text.from_json(model_data)
s = cls(text=reconstituted_model.make_short_sentence(140))
s.save()
return s

Calling create() from the manage.py shell works. It throws exceptions when it tries to use a text that isn't unique but that's expected, and I handle it in my management command. (At least I think I do!)

Here's the custom manager command I wrote:

from django.core.management.base import BaseCommand
from django.db import IntegrityError

from corpus.models import Sentence


class Command(BaseCommand):
help = 'Generates a sentence based on the current text model.'

def handle(self, *args, **options):
s = None
while not s:
try:
s = Sentence.create()
except IntegrityError:
pass
return s

When I try calling that command I get this traceback, that I can't make sense of:

Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/frunt/environments/betterbot/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/frunt/environments/betterbot/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/frunt/environments/betterbot/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/frunt/environments/betterbot/lib/python3.5/site-packages/django/core/management/base.py", line 354, in execute
self.stdout.write(output)
File "/Users/frunt/environments/betterbot/lib/python3.5/site-packages/django/core/management/base.py", line 107, in write
if ending and not msg.endswith(ending):
AttributeError: 'Sentence' object has no attribute 'endswith'

Can anyone explain what's going on?

/r/djangolearning
https://redd.it/5inuf8
Suggestions for dev and stable branch workflows with respect to PostgreSQL database.

So far, I've never worked with multiple git branches, I was always pushing my changes to 'master' branch and pulling them from the production server. Now, I want to create another 'dev' branch from 'master' branch and 'merge' the changes only after completion of some tests. But what I am thinking is I shall have an exact replica of my production server's PostgreSQL database on my laptop too for testing purposes which I should link to my 'master' branch's local_settings.py file. Then I should have a replica of this database once again with a different name and link it to my 'dev' branch's local_settings.py file. Am I thinking in the right way ? Any suggestions or better ways ? I am ready to refer to any documentation if required.

/r/django
https://redd.it/5j57vp
Notebook seems stuck

I have created a notebook where I'm defining a multibody system in order to obtain its kinematics and dynamics. I use the KanesMethod (from sympy) in order to obtain the equations of motion of the system.

However when I try to use trigsimp() on the mass matrix obtained, it seems to get stuck there forever (displaying an 'In[*]' next to that line).

The line is: 'mass_matrix = trigsimp(kane.mass_matrix)'
Here's a screenshot: https://gyazo.com/8c6ac6cefd87b889a4ed8f9a9c3077d9

I have little experience with python and ipython/jupyter, so I'm wondering what might be the reason for this.

/r/IPython
https://redd.it/4vomds
Wordpress and django

I am still trying to wrap my head around pointing my Django app to a Wordpress blog.

People seem to state the easiest is having blog.website.com on another server.

So I want to get this straight. Should my Django app be www.djangoapp.com and my blog be at www.fakeblog.com

Then I somehow have blog.djangoapp.com point to www.fakeblog.com?

If so, is this done through CNAME, redirect, alias?

Thanks for all the help

/r/djangolearning
https://redd.it/5idyt3
Generate an ipython notebook from code

I need to execute long running processes that generate a lot of data. I'd like to have an ipython notebooke linked to the h5 files that my simulations put out to facilitate an interactive analysis.

So: process -> hdf5 file -> ipython notebook with fancy plots.

I can go through the template route but I am wondering if there is a better way.

Ideas?



/r/IPython
https://redd.it/4v0mry