r/Pyramid•
nohtyp

Ask /r/Pyramid: Have you written any "single-file" applications in Pyramid?

I have tried to write "single-file" applications in Bottle, Flask, Tornado and a couple of other frameworks. My motivation for doing is is that I use Vim. In Vim, I can fold sections of a file and name them, that's actually much better than having files spread around in different folders. ( I am a lone gunman)

Watch this video to see what I mean. Skip to 3:50 to see the folds in all their glory. http://vimcasts.org/episodes/how-to-fold/

Another advantage is that I don't have to remember where a class or a function is, it's just right there or it's just a "zi" away.

Pyramid allows me to write applications in such a way. Can you share any tips or examples of Pyramid applicatons written this way?

Posted Dec 17, 2012, 5:18 AM UTC

813
mcdonc•

This is more of a general Python question than a Pyramid-specific one, and you'd likely be better off asking on the Python subreddit; a "single file Pyramid application" in the broader sense is just a "Python script that happens to use Pyramid as a library" and tips for Python scripts are all the same no matter which libraries the script uses.

5
nohtypOP•

Quite right. My bad.

1
nohtypOP•
2
raydeo•

The code examples from my authentication demo are all single file applications.

https://github.com/mmerickel/pyramid_auth_demo

2
nohtypOP•

I am actually going through your code since yesterday to understand how auth works in Pyramid. Thanks. This repo is a great resource for Pyramid beginners.

1
Teifion•

Sadly not, the smallest app I've written in Pyramid was Scrabble and though I could probably have squeezed it into a single file, it would have been messy.

Github link

1
nohtypOP•

Messy yes, unless you organize it well. I find that having lot's of files and switching between them has a heavy toll on the "flow". I lose the "big picture".

1
therealfakemoot•

There's always splitting your screen into multiple buffers. Also, if you're isolating your software components effectively, the 'big picture' should actually be a series of very small, understandable pictures.

3
firstpageguy•

Are you able to establish an equivalent flow while switching between buffers?

1
therealfakemoot•

Nope. I've never been able to stand files longer than a few hundred lines of code. I always separate my projects into components and use namespacing and import mechanics for loose coupling.

2
nohtypOP•

There's always splitting your screen into multiple buffers.

I wish there was a split collapse feature in Vim which would shrink a split to just one line showing only the first line, which would contain a narrative comment about what's in the file.

I personally use splits all the time. In fact I have the spacebar as the <leader> and navigating between splits using the below keymappings has become second nature.

nmap <leader>j <C-W>j
nmap <leader>k <C-W>k
nmap <leader>h <C-W>h
nmap <leader>l <C-W>l

Also, if you're isolating your software components effectively, the 'big picture' should actually be a series of very small, understandable pictures.

Modularization has nothing to do with how the source code is organized. I'll in fact argue breaking apart the source code in files after having modularized it using functions creates cognitive dissonance. I code in Python and splitting across source code in numerous files feels like Java to me.

This is just an experiment. I might be wrong about all this. But I want to try it. I have seen lots of people using a single source file for development.

1
dddbbb•

I wish there was a split collapse feature in Vim which would shrink a split to just one line showing only the first line, which would contain a narrative comment about what's in the file.

You mean like <C-w>_ or <C-w>| (to make the current window big)? Or more like :resize 1 or :vert resize 1 (to make the current window small)? I guess you'd need a normal gg to move to the first line with your narrative comment.

1