top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

Does python have preprocessor directives

+1 vote
165 views

Are there Python 'preprocessor directives'?
I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How?

posted May 28, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

1.Python doesn't define a preprocessor, and CPYthon doesn't implement one. Nothing to stop you from doing so, however.
2.It's quite possible that you don't need a preprocessor do what you want, since Python does much less compile-time checking than C. Also, it's possible to store function objects and module objects in variables, and thus to hide many things from the body of the code.
One biggie is print, since that's a reserved word (and a statement) in Python 2.x. But if you're using 2.7 you can use from __future__ import print, or something like that, and just use 3.x function semantics.

answer May 28, 2013 by anonymous
Similar Questions
+3 votes

I have the following string:

nginx_conf = '''
server {
 listen 80;
 server_name dev.{project_url};

 location / {
 proxy_pass http://127.0.0.1:8080;
 include /etc/nginx/proxy.conf;
 }

 location /media {
 alias /home/mariano/PycharmProjects/{project_name}/{project_name}/media;
 expires 30d;

 }
 location /static {
 alias /home/mariano/PycharmProjects/{project_name}/{project_name}/static;
 expires 30d;
 }

 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root html;
 }
}'''

And I want to format like this:

context = {
 "project_name":project_name,
 "project_url":project_url,
 }

nginx_conf.format(**context)

but since the string have { i can't. Is there a way to solve this?

0 votes

This isnt a huge issue, but I am wondering. I am running Mac OS X, I tried to configure with --with-valgrind and this is the error that I got:

configure: error: Valgrind support requested but headers not available

Now, I have valgrind installed, so it should work, yes?If someone has any extra info on this, Id appreciate it.

+1 vote

Can someone please explain data hiding in python through a program ?

+1 vote

A list can contain different types of elements but I am not able to understand how max () method work with different types of data elements.


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...