I have some issue putting variable into the path [duplicate]
up vote
-2
down vote
favorite
This question already has an answer here:
How do I put a variable inside a String in Python?
6 answers
it 's possible to put a variable into the path in python/linux
for example :
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))
I have syntax error when i do that.
python linux variables
marked as duplicate by Daniel Roseman, usr2564301, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 15:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-2
down vote
favorite
This question already has an answer here:
How do I put a variable inside a String in Python?
6 answers
it 's possible to put a variable into the path in python/linux
for example :
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))
I have syntax error when i do that.
python linux variables
marked as duplicate by Daniel Roseman, usr2564301, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 15:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
The documentation might be helpful here
– DavidG
Nov 12 at 9:59
@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.
– Adam Mitchell
Nov 12 at 10:59
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
This question already has an answer here:
How do I put a variable inside a String in Python?
6 answers
it 's possible to put a variable into the path in python/linux
for example :
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))
I have syntax error when i do that.
python linux variables
This question already has an answer here:
How do I put a variable inside a String in Python?
6 answers
it 's possible to put a variable into the path in python/linux
for example :
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))
I have syntax error when i do that.
This question already has an answer here:
How do I put a variable inside a String in Python?
6 answers
python linux variables
python linux variables
edited Nov 12 at 10:29
betontalpfa
8351023
8351023
asked Nov 12 at 9:56
Castelo
11
11
marked as duplicate by Daniel Roseman, usr2564301, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 15:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Daniel Roseman, usr2564301, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 15:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
The documentation might be helpful here
– DavidG
Nov 12 at 9:59
@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.
– Adam Mitchell
Nov 12 at 10:59
add a comment |
The documentation might be helpful here
– DavidG
Nov 12 at 9:59
@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.
– Adam Mitchell
Nov 12 at 10:59
The documentation might be helpful here
– DavidG
Nov 12 at 9:59
The documentation might be helpful here
– DavidG
Nov 12 at 9:59
@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.
– Adam Mitchell
Nov 12 at 10:59
@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.
– Adam Mitchell
Nov 12 at 10:59
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
You could use an f-string if you’re working in python 3.6+
This is the most efficient method.
counter = 0
filepath = f"/home/user/image{counter}.jpeg"
image = ClImage(file_obj=open(filepath, 'rb'))
Otherwise the second best would be using the .format() function:
counter = 0
filepath = "/home/user/image{0}.jpeg".format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
add a comment |
up vote
1
down vote
You can use Python's .format() method:
counter = 0
filepath = '/home/user/image{0}.jpeg'.format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
add a comment |
up vote
1
down vote
You need string concatenation.
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You could use an f-string if you’re working in python 3.6+
This is the most efficient method.
counter = 0
filepath = f"/home/user/image{counter}.jpeg"
image = ClImage(file_obj=open(filepath, 'rb'))
Otherwise the second best would be using the .format() function:
counter = 0
filepath = "/home/user/image{0}.jpeg".format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
add a comment |
up vote
2
down vote
You could use an f-string if you’re working in python 3.6+
This is the most efficient method.
counter = 0
filepath = f"/home/user/image{counter}.jpeg"
image = ClImage(file_obj=open(filepath, 'rb'))
Otherwise the second best would be using the .format() function:
counter = 0
filepath = "/home/user/image{0}.jpeg".format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
add a comment |
up vote
2
down vote
up vote
2
down vote
You could use an f-string if you’re working in python 3.6+
This is the most efficient method.
counter = 0
filepath = f"/home/user/image{counter}.jpeg"
image = ClImage(file_obj=open(filepath, 'rb'))
Otherwise the second best would be using the .format() function:
counter = 0
filepath = "/home/user/image{0}.jpeg".format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
You could use an f-string if you’re working in python 3.6+
This is the most efficient method.
counter = 0
filepath = f"/home/user/image{counter}.jpeg"
image = ClImage(file_obj=open(filepath, 'rb'))
Otherwise the second best would be using the .format() function:
counter = 0
filepath = "/home/user/image{0}.jpeg".format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
edited Nov 12 at 10:49
answered Nov 12 at 10:44
Jaba
6,786165292
6,786165292
add a comment |
add a comment |
up vote
1
down vote
You can use Python's .format() method:
counter = 0
filepath = '/home/user/image{0}.jpeg'.format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
add a comment |
up vote
1
down vote
You can use Python's .format() method:
counter = 0
filepath = '/home/user/image{0}.jpeg'.format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
add a comment |
up vote
1
down vote
up vote
1
down vote
You can use Python's .format() method:
counter = 0
filepath = '/home/user/image{0}.jpeg'.format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
You can use Python's .format() method:
counter = 0
filepath = '/home/user/image{0}.jpeg'.format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
answered Nov 12 at 10:02
Adam Mitchell
7331627
7331627
add a comment |
add a comment |
up vote
1
down vote
You need string concatenation.
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))
add a comment |
up vote
1
down vote
You need string concatenation.
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))
add a comment |
up vote
1
down vote
up vote
1
down vote
You need string concatenation.
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))
You need string concatenation.
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))
edited Nov 12 at 10:06
Lie Ryan
44.3k968121
44.3k968121
answered Nov 12 at 10:03
betontalpfa
8351023
8351023
add a comment |
add a comment |
The documentation might be helpful here
– DavidG
Nov 12 at 9:59
@Castelo If an answer here has helped you, standard practice on SO is to accept it. Please accept which ever answer helped you the most.
– Adam Mitchell
Nov 12 at 10:59