473,738 Members | 11,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return the last item in a list


I've googled for the above and get way too many hits..

I'm looking for an 'easy' way to have the last item in a list returned.

I've thought about

list[len(list)-1]

but thought there would be a more gracefull way.

Jul 18 '05
15 3645
On 31 Mar 2005 00:51:21 -0800, Serge Orlov <Se*********@gm ail.com> wrote:
Roman Yakovenko wrote:
Hi. I have small problem. I need to load extension module that depends
on shared library. Before actually importing module I tried to edit
os.environ or to call directly to os.putenv without any success -
shared library was not found. I tried to search the Internet for the
answer. The only approach I saw was to set LD_LIBRARY_PATH before
invoking python script. I don't like this solution.


Looks like it's glibc linker inflexibility:
http://hathawaymix.org/Weblog/2004-12-30
"""
There is no provision for modifying the library search path once your
program has started.
"""


Thanks, well small script around my program will make the trick. I
think I have no other choise.
Python does update enviromental variables if you change os.environ or
call os.putenv, but the linker ignores the changes.
Serge.

--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #11
Roman Yakovenko wrote:
Thanks for help. But it is not exactly solution I am looking for. I
would like to do it from python script. For example

update_env() #<- this function will change LD_LIBRARY_PATH
import extension_that_ depends_on_shar ed_library

Roman

On Mar 31, 2005 9:35 AM, John Abel <jo*******@pa.p ress.net> wrote:
With Solaris 8+ you would use the command crle, with Linux
(RedHat/SuSE/Mandrake) you need to add the relevant directories
/etc/ld.so.conf and run ldconfig. I've not got a Debian box to hand, so
I can't say if it matches, but that should give you a pointer.

I think I should have permissions to do it. (more over users of my
scripts should have permissions )


Yep. Unfortunatly if you don't have access to the /etc/ld.so.conf file,
the only option left is your wrapper script idea. (By the way, have you
actually tested to see if setting the LD_LIBRARY_PATH actually works? If
not, you're really up the creek.)

If the script is in shell, you could use something like:

(Dotted lines denote start and end of script, not actual script content)
-----------------------------------------------------------
#!/bin/sh
if ! echo ${LD_LIBRARY_PA TH} | /bin/fgrep -q "/path/to/your/library" then
export LD_LIBRARY_PATH =$oldpath":/path/to/your/library"
fi
<wrapped program> $*
-----------------------------------------------------------

This will check to see if your library path is in the LD_LIBRARY_PATH ,
set it if it's not, and then run your wrapped program, passing it the
arguments that the wrapper script was called by.

Joal
Jul 18 '05 #12
Joal Heagney wrote:
Roman Yakovenko wrote:
Thanks for help. But it is not exactly solution I am looking for. I
would like to do it from python script. For example

update_env() #<- this function will change LD_LIBRARY_PATH
import extension_that_ depends_on_shar ed_library

Roman

On Mar 31, 2005 9:35 AM, John Abel <jo*******@pa.p ress.net> wrote:
With Solaris 8+ you would use the command crle, with Linux
(RedHat/SuSE/Mandrake) you need to add the relevant directories
/etc/ld.so.conf and run ldconfig. I've not got a Debian box to hand, so
I can't say if it matches, but that should give you a pointer.


I think I should have permissions to do it. (more over users of my
scripts should have permissions )

Yep. Unfortunatly if you don't have access to the /etc/ld.so.conf file,
the only option left is your wrapper script idea. (By the way, have you
actually tested to see if setting the LD_LIBRARY_PATH actually works? If
not, you're really up the creek.)

If the script is in shell, you could use something like:

(Dotted lines denote start and end of script, not actual script content)
-----------------------------------------------------------
#!/bin/sh
if ! echo ${LD_LIBRARY_PA TH} | /bin/fgrep -q "/path/to/your/library" then
export LD_LIBRARY_PATH =$oldpath":/path/to/your/library"
fi
<wrapped program> $*
-----------------------------------------------------------

This will check to see if your library path is in the LD_LIBRARY_PATH ,
set it if it's not, and then run your wrapped program, passing it the
arguments that the wrapper script was called by.

Joal


Aaaarrrrggghhhh . Too long since I've programmed in script. Plus it
doesn't help changing your mind about implementation halfway through.
The script should read something like this:

-----------------------------------------------------------
#!/bin/sh
if ! echo ${LD_LIBRARY_PA TH} | /bin/fgrep -q "/path/to/your/library"
then
export LD_LIBRARY_PATH =$LD_LIBRARY_PA TH":/path/to/your/library"
fi
<wrapped program> $*
-----------------------------------------------------------

Sorry about that.

pretending-like-a-cat-that-he-didn't-just-do-something-stupid'ly yours,

Joal
Jul 18 '05 #13
Op 2005-03-31, Joal Heagney schreef <jo**@bigpond.n et.au>:
Joal Heagney wrote:
Roman Yakovenko wrote:
Thanks for help. But it is not exactly solution I am looking for. I
would like to do it from python script. For example

update_env() #<- this function will change LD_LIBRARY_PATH
import extension_that_ depends_on_shar ed_library

Roman

On Mar 31, 2005 9:35 AM, John Abel <jo*******@pa.p ress.net> wrote:

With Solaris 8+ you would use the command crle, with Linux
(RedHat/SuSE/Mandrake) you need to add the relevant directories
/etc/ld.so.conf and run ldconfig. I've not got a Debian box to hand, so
I can't say if it matches, but that should give you a pointer.

I think I should have permissions to do it. (more over users of my
scripts should have permissions )

Yep. Unfortunatly if you don't have access to the /etc/ld.so.conf file,
the only option left is your wrapper script idea. (By the way, have you
actually tested to see if setting the LD_LIBRARY_PATH actually works? If
not, you're really up the creek.)

If the script is in shell, you could use something like:

(Dotted lines denote start and end of script, not actual script content)
-----------------------------------------------------------
#!/bin/sh
if ! echo ${LD_LIBRARY_PA TH} | /bin/fgrep -q "/path/to/your/library" then
export LD_LIBRARY_PATH =$oldpath":/path/to/your/library"
fi
<wrapped program> $*
-----------------------------------------------------------

This will check to see if your library path is in the LD_LIBRARY_PATH ,
set it if it's not, and then run your wrapped program, passing it the
arguments that the wrapper script was called by.

Joal


Aaaarrrrggghhhh . Too long since I've programmed in script. Plus it
doesn't help changing your mind about implementation halfway through.
The script should read something like this:

-----------------------------------------------------------
#!/bin/sh
if ! echo ${LD_LIBRARY_PA TH} | /bin/fgrep -q "/path/to/your/library"
then
export LD_LIBRARY_PATH =$LD_LIBRARY_PA TH":/path/to/your/library"
fi
<wrapped program> $*
-----------------------------------------------------------


And you should change that last line to:

<wrapped program> "$@"
--
Antoon Pardon
Jul 18 '05 #14
Antoon Pardon wrote:
Op 2005-03-31, Joal Heagney schreef <jo**@bigpond.n et.au>:
Joal Heagney wrote:
Roman Yakovenko wrote:
Thanks for help. But it is not exactly solution I am looking for. I
would like to do it from python script. For example

update_env( ) #<- this function will change LD_LIBRARY_PATH
import extension_that_ depends_on_shar ed_library

Roman

On Mar 31, 2005 9:35 AM, John Abel <jo*******@pa.p ress.net> wrote:
>With Solaris 8+ you would use the command crle, with Linux
>(RedHat/SuSE/Mandrake) you need to add the relevant directories
>/etc/ld.so.conf and run ldconfig. I've not got a Debian box to hand, so
>I can't say if it matches, but that should give you a pointer.

I think I should have permissions to do it. (more over users of my
scripts should have permissions )
Yep. Unfortunatly if you don't have access to the /etc/ld.so.conf file,
the only option left is your wrapper script idea. (By the way, have you
actually tested to see if setting the LD_LIBRARY_PATH actually works? If
not, you're really up the creek.)

If the script is in shell, you could use something like:

(Dotted lines denote start and end of script, not actual script content)
-----------------------------------------------------------
#!/bin/sh
if ! echo ${LD_LIBRARY_PA TH} | /bin/fgrep -q "/path/to/your/library" then
export LD_LIBRARY_PATH =$oldpath":/path/to/your/library"
fi
<wrapped program> $*
-----------------------------------------------------------

This will check to see if your library path is in the LD_LIBRARY_PATH ,
set it if it's not, and then run your wrapped program, passing it the
arguments that the wrapper script was called by.

Joal


Aaaarrrrggghh hh. Too long since I've programmed in script. Plus it
doesn't help changing your mind about implementation halfway through.
The script should read something like this:

-----------------------------------------------------------
#!/bin/sh
if ! echo ${LD_LIBRARY_PA TH} | /bin/fgrep -q "/path/to/your/library"
then
export LD_LIBRARY_PATH =$LD_LIBRARY_PA TH":/path/to/your/library"
fi
<wrapped program> $*
-----------------------------------------------------------

And you should change that last line to:

<wrapped program> "$@"


Ah yes, because we want the arguments passed in as seperate words, not
as a whole string.

Serves me right for testing this out as:

#!/bin/sh
echo $*

:)

Joal
Jul 18 '05 #15
On Fri, 01 Apr 2005 01:13:03 GMT, rumours say that Joal Heagney
<jo**@bigpond.n et.au> might have written:
<wrapped program> $*
-----------------------------------------------------------

And you should change that last line to:

<wrapped program> "$@"


Ah yes, because we want the arguments passed in as seperate words, not
as a whole string.


No, this would happen if your last line was

<wrapped program> "$*"
To summarize, suppose your script is called with the following
arguments:

<wrapper_script > "File with space.txt" arg2 arg3

Here follow "last lines" and the corresponding sys.argv[1:]:

LAST LINE: <wrapped_progra m> $*
SYS.ARGV : ["File", "with", "space.txt" , "arg2", "arg3"]

LAST LINE: <wrapped_progra m> "$*"
SYS.ARGV : ["File with space.txt arg2 arg3"]

LAST LINE: <wrapped_progra m> "$@"
SYS.ARGV : ["File with space.txt", "arg2", "arg3"]

For more information, see man 1 bash or man 1 ksh or man 1 sh. Don't
know if this applies to *csh family.
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 18 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
4150
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:" sections in a "foreach" block The problem: The foreach statement allows iterating over all the...
12
4127
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport) {
10
14441
by: tkpmep | last post by:
For any list x, x.index(item) returns the index of the FIRST occurrence of the item in x. Is there a simple way to identify the LAST occurrence of an item in a list? My solution feels complex - reverse the list, look for the first occurence of the item in the reversed list, and then subtract its index from the length of the list - 1, i.e. LastOcc = len(x) - 1 - x.index(item) Is there a simpler solution?
0
1671
by: inandout | last post by:
Hi, I was wondering if anyone can help me with this. I have a listview that is specified to a size of: 348W x 308H When items are added to it, no problems. However when items continue to be added such that the list gets too large to be displayed, the scrollbars appear. Once this occurs, the last item though selected and focused (highlighted blue), will not appear within the viewable area since the listview requires a scrolldown. This...
23
18074
by: Florian Lindner | last post by:
Hello, can I determine somehow if the iteration on a list of values is the last iteration? Example: for i in : if last_iteration: print i*i else:
15
2873
by: buddhatown | last post by:
Very simple question for all you folks out there. I am total noob with js. I have a list called drawPathList thats just a list of xy coordinates. I use this to construct a drawing on a map. However, people would like to be able to 'Undo' something that they have drawn, so I'd like to yank that last item in a given list. drawPathList looks like this: 23,34||45,67||456,678||43,78 Can someone help me with a function to remove the...
4
3934
by: z060053 | last post by:
#include <iostream> using namespace std; template <class T>class list{ protected: typedef struct node{ node* prev; T* data; node* next; }; node* first;
5
15599
by: dudeja.rajat | last post by:
Sorry : Earlier mail had a typo in Subject line which might look in-appropriate to my friends Hi, I've a list some of whose elements with character \. I want to delete this last character from the elements that have this character set at their end,
0
1137
by: Fredrik Lundh | last post by:
dudeja.rajat@gmail.com wrote: explicitly comparing against true is bad style; better write that as if item.endswith('\\'): item.endswith("\\") works just fine:
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.