What is the perl's equivalent of repr in python/ruby's inspect method
I think you are looking for Data::Dumper
; see the documentation for some examples.
Best way to control library versions and sys.path for a Python command-line application
This largely depends upon the audience.
For developers, a good idea is indeed
- Include requirements.txt
- pip install -r requirements.txt
For end users, I'd recommend one of the follow:
- py2exe
- py2app
- cx_Freeze
From this other StackOverflow answer, pbundler may also be helpful.
What are R's equivalents to Perl's map and grep?
R has "grep", but it works entirely different than what you're used to. R has something much better built in: it has the ability to create array slices with a boolean expression:
a1 <- c(1:8)
a2 <- a1 [a1 %% 2 == 0]
a2
[1] 2 4 6 8
For map, you can apply a function as you did above, but it's much simpler to just write:
a2 * 2
[1] 4 8 12 16
Or in one step:
a1[a1 %% 2 == 0] * 2
[1] 4 8 12 16
I have never heard of a Perl to R phrase book, if you ever find one let me know! In general, R has less documentation than either perl or python, because it's such a niche language.
Ruby's times method and for loop does the same thing, but what are the respective processes?
Using the IRB
you can create an array that represents all the numbers from
to to
:
irb(main):043:0> from=10
=> 10
irb(main):044:0> to=20
=> 20
irb(main):047:0> a=(from..to).to_a
=> [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
You can get a sum
of that array:
irb(main):048:0> a.sum
=> 165
And, actually, you don't need to make an array at all:
irb(main):049:0> (from..to).sum
=> 165
Side note. If you have three dots the last value of to
is not included and that is a different sum obviously:
irb(main):053:0> (from...to).to_a
=> [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
irb(main):054:0> (from...to).sum
=> 145
So upto
should really be called uptoandincluding
:
irb(main):055:0> from.upto(to).to_a
=> [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
You can also use reduce
or the alias inject
either with a block or symbol to an operation to reduct a list the the pairwise application of the operator.
Example (reduce
and inject
are the same, but I usually use inject with a block or reduce with the parenthesis):
# block form where n is repeatedly added to an accumulator
irb(main):058:0> (from..to).inject{|sum, n| sum+n}
=> 165
# the operator + is repeated applied from the left to right
irb(main):059:0> (from..to).reduce(:+)
=> 165
Does Django have an equivalent of Rails's bundle install?
You can freeze requirements. This generates a list of all the Python modules that your project needs. I believe bundle
is similar in concept.
For example:
virtualenv --no-site-packages myproject_env # create a blank Python virtual environment
source myproject_env/bin/activate # activate it
(myproject_env)$ pip install django # install django into the virtual environment
(myproject_env)$ pip install other_package # etc.
...
(myproject_env)$ pip freeze > requirements.txt
The last line generates a text file will all the packages that were installed in your custom environment. You can use that file to install the same requirements on other servers:
pip install -r requirements.txt
Of course you don't need to use pip
, you can create the requirements file by hand; it doesn't have any special syntax requirements. Just a package and (possibly) version identifier on each line. Here is a sample of a typical django project with some extra packages:
Django==1.4
South==0.7.4
Werkzeug==0.8.3
amqplib==1.0.2
anyjson==0.3.1
celery==2.5.1
django-celery==2.5.1
django-debug-toolbar==0.9.4
django-extensions==0.8
django-guardian==1.0.4
django-picklefield==0.2.0
kombu==2.1.4
psycopg2==2.4.5
python-dateutil==2.1
six==1.1.0
wsgiref==0.1.2
xlwt==0.7.3
Do pip packages differ for different Operating System?
If the package contains C or other compiled language code - yes. This is why wheels have long complicated names detailing the OS and other variables.
Make setting up a venv part of your deployment. That should solve the problem.
Configure virtualenv content path instead of .venv/local/bin/activate
It's a bug in setuptools, source: https://github.com/pypa/setuptools/issues/3278
Related Topics
Using Beautifulsoup to Extract Text Without Tags
Pandas: Replace Substring in String
Passing a Matplotlib Figure to HTML (Flask)
How to Compile Opencv for iOS7 (Arm64)
Numpy/Scipy Equivalent of R Ecdf(X)(X) Function
Swift If Or/And Statement Like Python
How to Exchange Keys with Values in a Dictionary
How to Implement a Tree in Python
How to Multiply All Items in a List Together with Python
Preserving Styles Using Python's Xlrd,Xlwt, and Xlutils.Copy
How to Change an Image Size in Pygame
Pandas Read_HTML Valueerror: No Tables Found
I Can't Import Python Modules in Xcode 11 Using Pythonkit
Different Yaml Array Representations
How to Round a Floating Point Number Up to a Certain Decimal Place
Creating a List of Dictionaries Results in a List of Copies of the Same Dictionary